Skip to content

Commit

Permalink
SAM transform replace AutoPublishCodeSha256 (#3497)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Jul 12, 2024
1 parent defb6b7 commit a896807
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cfnlint/template/transforms/_sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def _replace_local_codeuri(self):
if k == "Ref":
if v in self._template.get("Parameters"):
self._parameters[v] = "Alias"
if isinstance(resource_dict.get("AutoPublishCodeSha256"), dict):
resource_dict["AutoPublishCodeSha256"] = "fakesha"
if resource_type in ["AWS::Serverless::LayerVersion"]:
if resource_dict.get("ContentUri"):
Transform._update_to_s3_uri("ContentUri", resource_dict)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Transform: AWS::Serverless-2016-10-31
Parameters:
Basepath:
Type: String
CodeBucket:
Type: String
GitCommit:
Type: String
Resources:
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
AutoPublishAlias: live
AutoPublishCodeSha256: !Ref GitCommit
CodeUri:
Bucket: !Ref CodeBucket
Key: !Sub ${ Basepath }/lambda.zip
DeploymentPreference:
Enabled: false
FunctionName: !Sub ${ AWS::StackName }
Handler: lambda.handler
MemorySize: 256
Runtime: python3.12
Timeout: 30
Tracing: PassThrough
34 changes: 34 additions & 0 deletions test/unit/module/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,37 @@ def test_sam_with_language_extension(self):
transformed_template = Transform(filename, template, region)
results = transformed_template.transform_template()
self.assertEqual(results, [])

def test_parameter_for_autopublish_code_sha256(self):
filename = (
"test/fixtures/templates/good/transform/auto_publish_code_sha256.yaml"
)
region = "us-east-1"
template = cfn_yaml.load(filename)
transformed_template = Transform(filename, template, region)
transformed_template.transform_template()
self.assertDictEqual(transformed_template._parameters, {})
self.assertDictEqual(
transformed_template._template.get("Resources")
.get("LambdaFunction")
.get("Properties"),
{
"Code": {
"S3Bucket": {"Ref": "CodeBucket"},
"S3Key": {"Fn::Sub": "${ Basepath }/lambda.zip"},
},
"Description": "fakesha",
"FunctionName": {"Fn::Sub": "${ AWS::StackName }"},
"Handler": "lambda.handler",
"MemorySize": 256,
"Role": {"Fn::GetAtt": ["LambdaFunctionRole", "Arn"]},
"Runtime": "python3.12",
"Tags": [{"Key": "lambda:createdBy", "Value": "SAM"}],
"Timeout": 30,
"TracingConfig": {"Mode": "PassThrough"},
},
)
self.assertIn(
"LambdaFunctionVersionfakesha",
transformed_template._template.get("Resources").keys(),
)

0 comments on commit a896807

Please sign in to comment.