Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for input and output artifacts in the Lambda invoke CodePipeline Action #1384

Closed
skinny85 opened this issue Dec 17, 2018 · 1 comment · Fixed by #1390
Closed
Assignees
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline

Comments

@skinny85
Copy link
Contributor

According to the reference documentation, a Lambda Action can have up to 5 inputs, and up to 5 outputs. We should allow modeling these in the Action.

Reported by @defel on our Gitter channel.

@skinny85 skinny85 added @aws-cdk/aws-codepipeline Related to AWS CodePipeline gap labels Dec 17, 2018
@skinny85 skinny85 self-assigned this Dec 17, 2018
@aweiher
Copy link
Contributor

aweiher commented Dec 17, 2018

Quoting discussion from gitter channel:

@defel [...] BTW, can you elaborate how do input artifacts work with Lambda Invoke Actions? How are the artifacts passed to the Lambda?

@skinny85 here is an example lambda function:

exports.handler = async (event) => {
    console.log('EV:', JSON.stringify(event));
    
    // .. handle codepipeline input artifacts ..
    // .. s3 upload output artifacts .. 
}

which outputs the following event:

{
    "CodePipeline.job": {
        "id": "ae5410b4-f587-4440-81fe-63754c01beb4",
        "accountId": "123123213",
        "data": {
            "actionConfiguration": {
                "configuration": {
                    "FunctionName": "InfrastructureStack-MyServiceDevEclECSECSClusterDe-JKL1ZHL8PE45"
                }
            },
            "inputArtifacts": [
                {
                    "location": {
                        "type": "S3",
                        "s3Location": {
                            "objectKey": "TEST_ecr-deploy-pipe/SourceArti/A0NL7zF",
                            "bucketName": "codepipeline-eu-central-1-123123213"
                        }
                    },
                    "revision": "sha256:ed82e395895e03986043c5c5dffc009f9bc5be00485318693bfd1941596f3b87",
                    "name": "SourceArtifact"
                }
            ],
            "outputArtifacts": [
                {
                    "location": {
                        "type": "S3",
                        "s3Location": {
                            "objectKey": "TEST_ecr-deploy-pipe/imageJson/1TQ1xBg",
                            "bucketName": "codepipeline-eu-central-1-123123213"
                        }
                    },
                    "revision": null,
                    "name": "imageJson"
                }
            ],
            "artifactCredentials": {
                "...": "..."
        }
    }
}

The job of the lambda function is now to upload the OutputArtifact (as as zip-file) like this (not tested but should work like this):

exports.handler = async (event) => {
    // input artifacts example:
    const inputArtifactLocation = ev["CodePipeline.job"].data.inputArtifacts[0].location.s3Location

    // output artifacts example: 
    const {bucketName, objectKey} = event["CodePipeline.job"].data.outputArtifacts[0].location.s3Location

    // user parameter example:
    const key = ev["CodePipeline.job"].data.actionConfiguration.configuration.UserParameters

    // upload output artifact to artifact-bucket:
    return s3.putObject({
        Bucket: bucketName,
        Key: objectKey,
        Body: // TODO: ... zip file ...
    }).promise().then(() => putJobSuccessResultAsync({
        jobId: event["CodePipeline.job"].id
    })).then(() => {

To complete this, here is how it looks in the aws console:

auswahl_060

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants