Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to describe AWS Lambda function test events in CloudFormation template?

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?

like image 613
Gleb Avatar asked Aug 10 '18 09:08

Gleb


People also ask

Which section of the CloudFormation template should you use to define your Lambda resources?

In an AWS CloudFormation template, you can specify a Lambda function as the target of a custom resource. Use custom resources to process parameters, retrieve configuration values, or call other AWS services during stack lifecycle events. The following example invokes a function that's defined elsewhere in the template.

How would you describe AWS Lambda?

AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. You can trigger Lambda from over 200 AWS services and software as a service (SaaS) applications, and only pay for what you use.


1 Answers

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'] 
like image 149
Sudharsan Sivasankaran Avatar answered Sep 22 '22 23:09

Sudharsan Sivasankaran