-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Fn::Transform #476
Comments
Agreed. Transforms and Macros are an area we need to work on. @cmmeyer and @melusom what would you like to see here? One approach would be to read the file and process it into the template just like the import would do. The other approach, sadly, would be to lint what we could. However this would require us to know what rules could break when a transform is used. Like we can't validate Refs or GetAtts to resources cause as in provided example all the resources don't exist. Basically the result would be a stripped down linting. Even harder is if you had the following template. The rules to check may change as Ref and GetAtts to other resources could now be checked.
That being said we have tried to not have much of a requirement on the network. Also we would have to hope the person running the cfn-lint would have read access to the template in the bucket (or have a profile setup for us to access it). |
Agreed @kddejong, it would be impossible to know whether missing Processing macros before running |
I would love to see the I would discourage doing this convergence within cfn-lint for network files, but it starts to outline a larger tool for local composition and deployment -- perhaps with pre-and-post macro evaluation linting phases. :) |
@cmmeyer brings up an interesting point regarding CI. It may happen that the file used for the If the approach will be not to evaluate network files, we will need to suppress the warnings above and we will also need to accept that users will receive false-positive "missing |
Just adding another opinion here. 😄 I think the choice to limit network and IAM role reliance is a good one. Any sort of change that requires actually hitting AWS resources is going to create a lot of issues in this repo with people trying to diagnose IAM issues, and that shouldn't be the focus of this repository. Since If the If the |
@spockNinja I can get on board with that approach. It won't fit all use cases but it makes a reasonable effort while avoiding IAM and network dependencies. |
@iDVB I think for your scenarios we can probably work on a fix. The hard part is that Transform can complete change templates. Ideally we would be linting the resulting template from Transforms. That being said I think we should be able to not fail those two rules if we run into Fn::Transform. |
Another example: Resources:
ApiName:
Type: AWS::Serverless::Api
Properties:
StageName: foo
DefinitionBody:
'Fn::Transform':
Name: AWS::Include
Parameters:
Location: swagger.yaml
FunctionName:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist
Handler: FunctionNameHandler.default
Runtime: nodejs10.x
Events:
FunctionNameEvent:
Type: Api
Properties:
Path: /foo
Method: post
RestApiId:
Ref: ApiName
RequestModel:
Model: RequestPayloadModel
Required: true The above template produces the error: cfn-lint is not executing the transform to include the local swagger.yaml file, which contains the RequestPayloadModel that it complains about! While running |
@hugoduraes, I sort have the same as you but I solved it differently, so: Api:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: resources/openapi.yaml and then in your x-amazon-apigateway-integration:
type: aws
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FunctionName.Arn}/invocations
httpMethod: POST
credentials:
Fn::Ref: MyRoleArn This way you will be able to deploy the template as you intended but you need to extend your swagger definition. @kddejong I noticed that the |
Will try it. Thanks @Nr18 👍 |
@Nr18 I've revisited my implementation and I've found that your suggestion is what I have at the moment. One thing you don't show in your comment is the template for your lambda function. What causes the issue are the RestApiId and RequestModel properties on the lambda function template. Do you have these on your template? |
@hugoduraes so in your example it should look like this: ApiName:
Type: AWS::Serverless::Api
Properties:
StageName: foo
DefinitionBody:
'Fn::Transform':
Name: AWS::Include
Parameters:
Location: swagger.yaml
FunctionName:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist
Handler: FunctionNameHandler.default
Runtime: nodejs10.x And then in your ...rest of the file...
x-amazon-apigateway-request-validators:
full:
validateRequestBody: true
validateRequestParameters: true
x-amazon-apigateway-request-validator: full
paths:
/foo:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RequestPayloadModel'
responses:
"200":
description: 200 Accepted
content:
application/json:
schema:
$ref: '#/components/schemas/Success'
x-amazon-apigateway-integration:
credentials:
Fn::GetAtt: FunctionNameRole.Arn
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FunctionName.Arn}/invocations
passthroughBehavior: when_no_templates
httpMethod: POST
type: aws
responses:
default:
statusCode: "200" # Bad Request
responseTemplates:
application/json: |
{
"Message": "Success"
}
...rest of the file... So you don't need the |
@Nr18 are the request parameters validated on API Gateway if I don't specify the |
Yes, the following section in the OpenAPI definition would take care of that: x-amazon-apigateway-request-validators:
full:
validateRequestBody: true
validateRequestParameters: true
x-amazon-apigateway-request-validator: full You could also place the |
I thought those two properties (RestApiId and RequestModel) were also needed for it to validate requests. I've updated my template and open api docs and everything is looking great now. Thanks @Nr18 However, the issue reported here remains. |
Is there a way to get cfn-lint to ignore this issue? I'm suffering from this same problem; Api:
Type: AWS::Serverless::Api
Properties:
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: resources/openapi.yaml
EDIT: I tried this api:
Type: AWS::Serverless::HttpApi
Metadata:
cfn-lint:
config:
ignore_checks:
- E0001 Which does not work |
@tkeeber you can workaround this issue by not defining the Resources:
ApiName:
Type: AWS::Serverless::Api
Properties:
StageName: foo
DefinitionBody:
'Fn::Transform':
Name: AWS::Include
Parameters:
Location: swagger.yaml
FunctionName:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./dist
Handler: FunctionNameHandler.default
Runtime: nodejs10.x
Events:
FunctionNameEvent:
Type: Api
Properties:
Path: /foo
Method: post
RestApiId:
Ref: ApiName
# RequestModel:
# Model: RequestPayloadModel
# Required: true |
Thanks @hugoduraes, but I do not currently have that defined |
This comment has been minimized.
This comment has been minimized.
api:
Type: AWS::Serverless::HttpApi
Metadata:
cfn-lint:
config:
ignore_checks:
- E0001 Add this to disable the linter error at resource level:- Resources:
WebsiteBucket:
Type: AWS::S3::Bucket
Metadata:
cfn-lint:
config:
ignore_checks:
- E3001
Fn::Transform:
Name: AWS::Include
Parameters:
Location: 's3://xxxxx'
...
... |
does it make sense to at least have the option to completely ignore linting when could we support something like this? Metadata:
cfn-lint:
config:
ignore_transform: true |
We've been hitting this for a while, in our case it's error E3002 Invalid Property when using |
This comment has been minimized.
This comment has been minimized.
That's because you do have duplicates. - "SubnetIds": [ {"Ref": "SubnetId001", "Ref": "SubnetId002", "Ref": "SubnetId003"} ]
+ "SubnetIds": [ { "Ref": "SubnetId001" }, { "Ref": "SubnetId002" }, { "Ref": "SubnetId003" } ] |
Just want to keep kicking this along. I had my sceptre/service catalog/cloudformation templates all working dandy, with Part of the problem is that the errors generated (E7001 and E7002 are two which we see, for example) are not errors we want to ignore in CICD. If cfn-python-lint was even just modified to return warnings when it sees that a mapping is involved we could at least ignore that warning in our CICD pipeline. Is there any foreseeable workaround for this? |
Hey, ran into this today, similar use-case as @qidydl 's . As noted above in @iamkhalidbashir 's workaround, I'm disabling E0001 in my POC to get past linting. |
Would be great to see resolution on this issue. Fundamentally, synthesizing the transform is an intractable problem, ignore it, perhaps with a message if possible so cfn-lint doesn't have to be disabled. |
Would be great to see this fixed. Currently getting a "W2001 Parameter not used" error for parameters I am referencing in my OAS.yaml. Snippet from template.yaml; Parameters:
IPWhitelist:
...
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
OpenApiVersion: 3.0.0
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: 'oas3.yaml' And snippet from oas3.yaml; x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Action: execute-api:Invoke
Resource: "execute-api:/*"
Effect: Allow
Principal: '*'
- Action: execute-api:Invoke
Resource: "execute-api:/*"
Effect: Deny
Condition:
NotIpAddress:
aws:SourceIp:
- Ref: IPWhitelist
Principal: '*' cfn-lint is exiting with I could define the IPWhitelist as Auth.ResourcePolicy.IpRangeWhitelist on the APIGateway resource in template.yaml as opposed to in oas3.yaml, but then that causes |
@evin-murphy this is a different issue. For SAM we run the template through the SAM translator and validate the output. The underlying issue with |
For the most part a lot of these issues should clear up with v1. A vast majority of rules are built to use json schema validation. As we hit the This logic isn't perfect as JSON schema can't be used for all the types of rules we have. So your mileage may very depending on how the rule was written and how you are doing the Transform. We can tackle those as one offs. Additionally if you are doing Fn::Transform inside another function or in different parts of the template you may see an issue but those are easily fixable inside v1. I tried to add a few of these already but may have missed a couple. Again we tackle these as they arise. For the original issue we still don't have anything to handle duplicate keys and that will continue to be an issue. |
In relation to the uniqueness of keys its worth noting from yaml specs Mapping
|
cfn-lint version: 0.7.4
Description of issue.
cfn-lint does not properly evaluate Fn::Transform.
Example:
Returns:
Additionally, multiple Fn::Transforms produce this error:
The template used which generated these errors passed
aws cloudformation validate-template
without error, so it is valid CFN syntax.The text was updated successfully, but these errors were encountered: