Skip to content

Transform fails to interpret dynamic references in a CodeUri S3 bucket path correctly #3399

@Tristano8

Description

@Tristano8

Description

It is not possible to use {{resolve:...}} syntax (CloudFormation Dynamic References) in an S3 bucket reference in the CodeUri field of (at least) AWS::Serverless::Function. To attach certain (Terraform-provisioned) S3 resources to our Functions' execution roles, we have been using dynamic references to SSM Parameters which provide the S3 bucket paths. Attempts to deploy lambdas that reference these bucket paths fail because Serverless Transform is incorrectly interpolating the CloudFormation Template. It appears that SAM interprets anything until the first / as the S3Bucket and anything after as the S3Key

Steps to reproduce

  • Create an S3 bucket and a zip file within it
  • Create an SSM Parameter (string type) whose value is the name of the bucket from step (1).
  • Declare an AWS::Serverless::Function which lists the S3 path to the file, using {{resolve}}:
ExampleFunction:
  Type: AWS::Serverless::Function
  # Other fields omitted
  CodeUri: "s3://{{resolve:ssm:/name_of_bucket_parameter_from_step_2}}/name_of_file.zip"
  • Attempt to deploy.

Observed result

Cloudformation deployment failure with Properties validation failed for resource <FunctionName> with message: #/Code/S3Bucket: failed validation constraint for keyword [pattern].

Processed template looks like this:

"Code": {
          "S3Bucket": "{{resolve:ssm:",
          "S3Key": "name_of_bucket_parameter_from_step_2}}/name_of_file.zip"
        },

Expected result

Serverless Transform would not inspect the string, and pass it through unchanged to be substituted by CloudFormation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions