Adding the "AWS Lambda invoke" action
This section describes how to add the AWS Lambda invoke action to your workflow. The AWS Lambda invoke action invokes a Lambda function that you specify.
In addition to invoking your function, the AWS Lambda invoke action also converts each top-level key in the response payload received from the Lambda function into a workflow output variable. These variables can then be referenced in subsequent workflow actions. If you don't want all top-level keys to be converted to variables, you can use filters to specify the exact ones. For more information, see ResponseFilters property description in the "AWS Lambda invoke" action reference.
Topics
When to use this action
Use this action if you want to add functionality to your workflow that is encapsulated in, and performed by, a Lambda function.
For example, you might want your workflow to send a Build started
notification to a Slack channel before starting a build of your application. In this case,
your workflow would include an AWS Lambda invoke action to invoke a Lambda
to send out the Slack notification, and a build action
to build your application.
As another example, you might want your workflow to conduct a vulnerability scan on your application before it is deployed. In this case, you would use a build action to build your application, an AWS Lambda invoke action to invoke a Lambda to scan for vulnerabilities, and a deploy action to deploy the scanned application.
Example workflow
Note
The following example workflow is for illustrative purposes only, and requires additional setup work in order to function properly. It is meant to give you an example of what a workflow might look like when it is configured with the AWS Lambda invoke action.
The following workflow includes the AWS Lambda invoke action, along with a deploy action. The workflow sends out a Slack notification indicating that a deployment has started, and then deploys an application into AWS using an AWS CloudFormation template. The workflow consists of the following building blocks that run sequentially:
-
A trigger – This trigger starts the workflow run automatically when you push a change to your source repository. For more information about triggers, see Working with triggers.
-
An AWS Lambda invoke action (
LambdaNotify
) – On trigger, this action invokes theNotify-Start
Lambda function in the specified AWS account and Region (my-aws-account
, andus-west-2
). On invocation, the Lambda function sends a Slack notification indicating a deployment has started. -
A Deploy AWS CloudFormation stack action (
Deploy
) – On completion of the AWS Lambda invoke action, the Deploy AWS CloudFormation stack action runs the template (cfn-template.yml
) to deploy your application stack. For more information about the Deploy AWS CloudFormation stack action, see Adding the "Deploy AWS CloudFormation stack" action.
Name: codecatalyst-lamda-invoke-workflow SchemaVersion: 1.0 Triggers: - Type: PUSH Branches: - main Actions: LambdaNotify: Identifier: aws/lambda-invoke@v1 Environment: Name: my-production-environment Connections: - Name: my-aws-account Role: codecatalyst-lambda-invoke-role Inputs: Sources: - WorkflowSource Configuration: Function: Notify-Start AWSRegion: us-west-2 Deploy: Identifier: aws/cfn-deploy@v1 Environment: Name: my-production-environment Connections: - Name: my-aws-account Role: codecatalyst-deploy-role Inputs: Sources: - WorkflowSource Configuration: name: my-application-stack region: us-west-2 role-arn: arn:aws:iam::111122223333:role/StackRole template: ./cfn-template.yml capabilities: CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND
Adding the "AWS Lambda invoke" action
Use the following instructions to add the AWS Lambda invoke action to your workflow.
Prerequisite
Before you begin, make sure your AWS Lambda function and associated Lambda execution role are ready and available in AWS. For more information, see the Lambda execution role topic in the AWS Lambda Developer Guide.
Variables produced by the "AWS Lambda invoke" action
When the AWS Lambda invoke action runs, it produces variables that you can use in subsequent workflow actions. For details, see "AWS Lambda invoke" action variables in the List of predefined variables.
"AWS Lambda invoke" action definition
The AWS Lambda invoke action is defined as a set of YAML properties inside your workflow definition file. For information about these properties, see "AWS Lambda invoke" action reference in the Workflow definition reference.