For some reason, it doesn't seem possible to specify CodeUri as a parameter.
I have a template that specifies a function:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A hello world application.
Parameters:
CodeUri:
Type: String
Description: The link to the code to use.
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
CodeUri: !Ref CodeUri
When I try to execute the template using aws cloudformation deploy the following error appears:
aws cloudformation deploy --stack-name example --template-file lambda-example.sam.yaml --parameter-overrides CodeUri=s3://$BUCKET_NAME/example.zip
Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HelloWorldFunction] is invalid. 'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter.
I tried running it with the --debug flag attached and it looks like the correct S3 Uri is added. Below is an extract from the debug output:
<Parameters>
<member>
<ParameterKey>CodeUri</ParameterKey>
<ParameterValue>s3://johannes-lambda-test/example.zip</ParameterValue>
</member>
</Parameters>
The example code that have been used can be found at https://github.com/Pelto/aws-serverless-2016-10-31-bug
I'm seeing the same with Join:
CodeUri: !Join [ "", [ "s3://", !Ref LambdaS3BucketName, "/example.zip" ] ]
'CodeUri' is not a valid S3 Uri of the form "s3://bucket/key" with optional versionId query parameter.
Yeah, this isn't supported yet. See #22
CloudFormation parameters have been enabled for CodeUri. However, you must specify values for Bucket and Key separately, e.g.
CodeUri:
Bucket: !Ref BucketName
Key: !Ref CodeKey
See the Using Intrinsic Functions paragraph in the SAM documentation for more information.
If the bucket and key are specified using a !Ref in this way, it appears there is no longer any way for aws cloudformation package to create a new zip bundle and transform the SAM template on its own. Is that correct?
Are there any workarounds that would allow packaging to continue in the absence of any CodeUri-related parameters? I was trying something like this to remove the Bucket and Key attributes without any luck:
CodeUri:
Bucket: !If [RequiresPackage, !Ref "AWS::NoValue", !Ref CodeUriBucket]
Key: !If [RequiresPackage, !Ref "AWS::NoValue", !Ref CodeUriKey]
Is there some weird divergence between the different components of Cloudformation, because I can leave CodeUri blank and its deploys without issue, but if I try to create a ChangeSet I see this error:
"Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Func] is invalid. Either 'InlineCode' or 'CodeUri' must be set"
So are ChangeSets just not compatible with SAM at all?
@red8888 how were you deploying before? Was it with the SAM or AWS CLI?
Most helpful comment
If the bucket and key are specified using a
!Refin this way, it appears there is no longer any way foraws cloudformation packageto create a new zip bundle and transform the SAM template on its own. Is that correct?Are there any workarounds that would allow packaging to continue in the absence of any
CodeUri-related parameters? I was trying something like this to remove the Bucket and Key attributes without any luck: