Vincent Claes
Vincent Claes

Reputation: 4768

How do I pass variables through AWS Codepipeline?

AWS CodePipeline orchestrates first lambda-A and then lambda-B and i want to pass a variable from my lambda-A to my lambda-B.

In lambda-A i set the outputVariables when setting the job to success:

boto3.client("codepipeline").put_job_success_result(
        jobId=event["CodePipeline.job"]["id"],
        outputVariables={"FOO":"BAR"}
    )

From the documentation i know that outputVariables are Key-value pairs that can be made available to a downstream action.

CodePipeline then triggers lambda-B. How can i retrieve in lambda-B the variables i have set in the outputVariables in lambda-A?

Upvotes: 0

Views: 1942

Answers (1)

shariqmaws
shariqmaws

Reputation: 8890

In Lambda-B's action configuration, in User parameters, enter the variable syntax to ingest the variable created in earlier action using this syntax:

#{outputVariables.FOO}

Then you can unpack the 'UserParameters' in Lambda function:

{
    "CodePipeline.job": {
        "id": "EXAMPLE-e08a-4f06-b9ba-EXAMPLE",
        "accountId": "EXAMPLE87397",
        "data": {
            "actionConfiguration": {
                "configuration": {
                    "FunctionName": "LambdaForCP-Python",
                    "UserParameters": "5e2591fd79889dEXAMPLE5f33e2"
                }
            },

from 'event':

def lambda_handler(event, context):

    print(event)

This procedure is detailed in Step (f) here:

Upvotes: 1

Related Questions