Adding the "AWS Lambda invoke" action - Amazon CodeCatalyst

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.

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 the Notify-Start Lambda function in the specified AWS account and Region (my-aws-account, and us-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.

Visual
To add the "AWS Lambda invoke" action using the visual editor
  1. Open the CodeCatalyst console at https://codecatalyst.aws/.

  2. Choose your project.

  3. In the navigation pane, choose CI/CD, and then choose Workflows.

  4. Choose the name of your workflow. You can filter by the source repository or branch name where the workflow is defined, or filter by workflow name.

  5. Choose Edit.

  6. Choose Visual.

  7. At the top-left, choose + Actions to open the action catalog.

  8. From the drop-down list, choose Amazon CodeCatalyst.

  9. Search for the AWS Lambda invoke action, and do one of the following:

    • Choose the plus sign (+) to add the action to the workflow diagram and open its configuration pane.

      Or

    • Choose AWS Lambda invoke. The action details dialog box appears. On this dialog box:

      • (Optional) Choose View source to view the action's source code.

      • Choose Add to workflow to add the action to the workflow diagram and open its configuration pane.

  10. In the Inputs, Configuration, and Outputs tabs, complete the fields according to your needs. For a description of each field, see the "AWS Lambda invoke" action reference. This reference provides detailed information about each field (and corresponding YAML property value) as it appears in both the YAML and visual editors.

  11. (Optional) Choose Validate to validate the workflow's YAML code before committing.

  12. Choose Commit, enter a commit message, and choose Commit again.

YAML
To add the "AWS Lambda invoke" action using the YAML editor
  1. Open the CodeCatalyst console at https://codecatalyst.aws/.

  2. Choose your project.

  3. In the navigation pane, choose CI/CD, and then choose Workflows.

  4. Choose the name of your workflow. You can filter by the source repository or branch name where the workflow is defined, or filter by workflow name.

  5. Choose Edit.

  6. Choose YAML.

  7. At the top-left, choose + Actions to open the action catalog.

  8. From the drop-down list, choose Amazon CodeCatalyst.

  9. Search for the AWS Lambda invoke action, and do one of the following:

    • Choose the plus sign (+) to add the action to the workflow diagram and open its configuration pane.

      Or

    • Choose AWS Lambda invoke. The action details dialog box appears. On this dialog box:

      • (Optional) Choose View source to view the action's source code.

      • Choose Add to workflow to add the action to the workflow diagram and open its configuration pane.

  10. Modify the properties in the YAML code according to your needs. An explanation of each available property is provided in the "AWS Lambda invoke" action reference.

  11. (Optional) Choose Validate to validate the workflow's YAML code before committing.

  12. Choose Commit, enter a commit message, and choose Commit again.

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.