-
Notifications
You must be signed in to change notification settings - Fork 598
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
New rule for Lambda zip deployment #2682
Conversation
Thanks @tal66 I'll take a look. I think this is a good start the big thing we have to cover for is when people use an intrinsic function (Fn::If, Ref, GetAtt, FindInMap, etc.). |
@tal66 When implementing
You can check the implementation of #2673, isn't simple to compare these cases including correctly check @tal66 @kddejong What do you think of this proposal Would generally solve the problem of implementing rules enforcing |
Do you mean templates such as this (*)? is there already a way that you use to resolve possible scenarios and attributes? (*) AWSTemplateFormatVersion: '2010-09-09'
Description: Properties with conditions.
Parameters:
UseZipDeployment:
Type: String
Default: true
AllowedValues:
- true
- false
Conditions:
IsZipDeployment:
!Equals [true, !Ref UseZipDeployment]
Resources:
Function1:
Type: AWS::Lambda::Function
Properties:
Role: arn:aws:iam::123456789012:role/lambda-role
Code:
!If
- IsZipDeployment
- S3Bucket: my-bucket
S3Key: my-lambda-function.zip
- ImageUri: 111122223333.dkr.ecr.us-east-1.amazonaws.com/app:latest
PackageType: !If [IsZipDeployment, "Zip", "Image"] (**) # Code:
ImageUri: String
S3Bucket: String
S3Key: String
S3ObjectVersion: String
ZipFile: String |
afaik,
For your example, a valid template for both
|
Not sure if everyone agree with this, what do you think?
we can opt to implement only simple cases of the following, ignoring the very complicated one AWSTemplateFormatVersion: "2010-09-09"
Conditions:
IsZipDeployment: !Equals [true, !Ref 'UseZipDeployment']
Description: Properties with conditions.
Parameters:
MyImage:
Type: String
MyImageVersion:
Type: String
UseZipDeployment:
AllowedValues:
- true
- false
Default: true
Type: String
Resources:
Bucket:
Properties:
BucketName: my-bucket
Type: AWS::S3::Bucket
SimpleLambdaImage:
Properties:
Code:
ImageUri: !Ref 'MyImage'
PackageType: Image
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
SimpleLambdaImageWithVersion:
Properties:
Code:
ImageUri: !Sub
- '${S}:${V}'
- S: !Ref 'MyImage'
V: !Ref 'MyImageVersion'
PackageType: Image
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
SimpleLambdaInplaceSource:
Properties:
Code:
ZipFile: !Sub
- |
def handler(event, context):
return "Hello World ${Region}"
- Region: !Ref 'AWS::Region'
Handler: index.handler
PackageType: Zip
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
SimpleLambdaZipLocalSource:
Properties:
Code: ./src
Handler: !Join
- '.'
- - index
- !Ref 'AWS::Region'
PackageType: Zip
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
SimpleLambdaZipS3:
Properties:
Code:
S3Bucket: !Ref 'Bucket'
S3Key: !Sub
- 'my-function-${R}'
- R: !Ref 'AWS::Region'
Handler: index.handler
PackageType: Zip
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
VeryComplicatedConditionUnlikelyToBeUsed:
Properties:
Code: !If
- IsZipDeployment
- S3Bucket: !Ref 'Bucket'
S3Key: !Sub
- "my-function-${R}"
- R: !Ref 'AWS::Region'
- ImageUri: 111122223333.dkr.ecr.us-east-1.amazonaws.com/app:latest
Handler: !If
- IsZipDeployment
- !Sub "my.${AWS::Region}.handler}"
- !Ref 'AWS::NoValue'
PackageType: !If
- IsZipDeployment
- "Zip"
- "Image"
Role: arn:aws:iam::123456789012:role/lambda-role
Type: AWS::Lambda::Function
|
src/cfnlint/rules/resources/lmbd/ZipPackageRequiredProperties.py
Outdated
Show resolved
Hide resolved
src/cfnlint/rules/resources/lmbd/ZipPackageRequiredProperties.py
Outdated
Show resolved
Hide resolved
src/cfnlint/rules/resources/lmbd/ZipPackageRequiredProperties.py
Outdated
Show resolved
Hide resolved
src/cfnlint/rules/resources/lmbd/ZipPackageRequiredProperties.py
Outdated
Show resolved
Hide resolved
Can you run and submit the updates?
|
(closes #2676)
Hi, implemented this new rule. what do you think?
*quick failure test:
cfn-lint test/fixtures/templates/bad/resources/lambda/zipfile_required_properties.yaml