I'm creating a Lambda through CloudFormation. The Function code path must be dynamic.
Here's my template:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Parameters:
LambdaBucketName:
Type: String
Description: The name S3 Bucket of the lambda function code
Resources:
FUNC:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'my-lambda-func'
Handler: index.handler
Runtime: nodejs18.x
CodeUri:
FunctionCode:
Bucket: !Ref LambdaBucketName
Key: my-lambda-func.zip
etc...
When it deploys, I get this Cfn error message:
ROLLBACK_IN_PROGRESS : 'CodeUri' requires Bucket and Key properties to be specified.
But documentation says it's ok to do this. AWS::Serverless::Function
CodeUri The function code's Amazon S3 URI, path to local folder, or FunctionCode object.
If I use just this:
CodeUri: s3://my-bucket/my-lambda-func.zip
It's fine because it's not dynamic. But if I try using that with !Ref (mapping), it won't work. Complains about the pattern.
If I try:
CodeUri:
Bucket: !Ref LambdaBucketName
Key: my-lambda-func.zip
Then I get a pattern error on Bucket. The ref'd bucket name is just a normal short string.
How can I get this to work?