I have following set of parameters:
"Parameters" : {
"DeployBucket" : {
"Type" : "String",
"Default": "a"
},
"DeployKey" : {
"Type" : "String",
"Default" : "b"
},
"DeployString": {
"Type" : "String",
"Default" : "s3://<some-bucket>/<somefile>"
}
}
in my template for testing.
If I use "CodeUri" : "s3://<my-bucket>/<my-file>", with AWS::Serverless::Function resource I run aws deploy properly.
Even using following
"CodeUri" : {
"Key": {"Ref": "DeployKey"},
"Bucket": {"Ref": "DeployBucket"}
}
and running aws deploy -parameter-overrides DeployBucket=<bucket-name> DeployKey=<file-name> works properly
As soon as I use
"CodeUri" : {"Ref": "DeployString"}
changeset creation fails with message:
FAILED - Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless
Application Specification document. Number of errors found: 1. Resource with
id [xxx] is invalid. 'CodeUri' requires Bucket and Key properties to be specified`
In this case I use aws deploy command without passing any parameters => stack creation should have used hardcoded parameter value from Parameters section.
Documentation states that usage of String or S3 location object is supported with CodeUri property. In this case it seems like Ref function can not be used to fetch string data for CodeUri property.
Yes! This is how it is supposed to work. You cannot directly !Ref the string. Instead you should use the {Bucket, Key} notation - https://github.com/awslabs/serverless-application-model/blob/master/HOWTO.md#using-intrinsic-functions
SAM needs to parse CodeUri string into bucket/key, but unfortunately it cannot resolve runtime parameter values passed through !Ref.
You cannot directly !Ref the string. Instead you should use the {Bucket, Key} notation
Well. Worth of mention on documentation.
Are there any plans to support this feature? It would be great to use the same Cloud Formation file both locally and when we deploy and passing the CodeUri as a CF parameter (locally the local folder/zip and the s3 bucket during deployment)
@zoltanhomoki as a workaround, set CodeUri as local path and when you want to deploy, s3 bucket deploymemt, use sam package
This is confusing since the documentation says you can use local file path:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-codeuri
CodeUri
The Amazon S3 URI, local file path, or FunctionCode object of the function code.
If an Amazon S3 URI or FunctionCode object is provided, the Amazon S3 object referenced must be a valid Lambda deployment package.
If a local file path is provided, the template must go through the workflow that includes the sam deploy or sam package command, in order for the code to be transformed properly.
_was using aws cloudformation create-stack command, will try with sam deploy_
Despite the mention of using sam deploy for proper handling when local file path is specified this didn't work when using !Ref (might work with direct value?).
Most helpful comment
Well. Worth of mention on documentation.