26
votes

I describe existing AWS Lambda function in CloudFormation template and I face with the next issue. In our Lambda we configured few test events which helps us to verify some usecases (I mean functionality from the screenshot below).

enter image description here

But I don't see any abilities to add these test events to the CloudFormation template. AWS documentation don't help me with that. Is that possible at all or are there any workarounds how to export and import Lambda function test events?

1
I found this question because it occurred to me that this would be useful ... so if anyone from aws reads this ... +1.RH Becker

1 Answers

8
votes

Lambda test functionality is available only in the UI console, You can use Cloudformation Custom Resource to invoke a function from a cloudformation template. Resource properties allow AWS CloudFormation to create a custom payload to send to the Lambda function.

Sample code:

Resources:
  EnableLogs:
    Type: Custom::EnableLogs
    Version: '1.0'
    Properties:
      ServiceToken: arn:aws:lambda:us-east-1:acc:function:rds-EnableRDSLogs-1O6XLL6LWNR5Z
      DBInstanceIdentifier: mydb

the event parameter provides the resource properties. ex:

event['ResourceProperties']['DBInstanceIdentifier']