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

[aws_codepipeline_actions] CloudFormationCreateUpdateStackAction action with cdk synth output fails #9911

Closed
jonathan-kosgei opened this issue Aug 22, 2020 · 5 comments
Assignees
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@jonathan-kosgei
Copy link

jonathan-kosgei commented Aug 22, 2020

I'm trying to deploy a basic pipeline for my lambda function as shown https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html using the below stack;

Reproduction Steps

from aws_cdk import (
    core,
    aws_codebuild as codebuild,
    aws_codepipeline as codepipeline,
    aws_codepipeline_actions as codepipeline_actions,
)

class PipelineStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        environment=codebuild.BuildEnvironment(
            build_image=codebuild.LinuxBuildImage.STANDARD_4_0,
        )

        cdk_build = codebuild.PipelineProject(self, "CDKBuild",
            environment=environment,
            build_spec=codebuild.BuildSpec.from_object(dict(
                version="0.2",
                phases=dict(
                    install={
                        "runtime-versions" : {
                            "python": "3.8",
                            "nodejs": "12",
                        },
                        "commands" : [
                            "npm install aws-cdk@1.60",
                            "python -m pip install -r requirements.txt"
                        ]
                    },
                    build=dict(commands=[
                        "npx cdk synth -o dist"])),
                artifacts={
                    "base-directory": "dist",
                    "files": [
                        "ApplicationStack.template.json"]},
            )))

        source_output = codepipeline.Artifact()
        cdk_build_output = codepipeline.Artifact("CdkBuildOutput")

        codepipeline.Pipeline(self, "Pipeline",
            stages=[
                codepipeline.StageProps(stage_name="Source",
                    actions=[
                        codepipeline_actions.GitHubSourceAction(
                            action_name="GitHub_Source",
                            owner="xx",
                            repo="xx",
                            output=source_output,
                            branch="master"
                        )]),
                codepipeline.StageProps(stage_name="Build",
                    actions=[
                        codepipeline_actions.CodeBuildAction(
                            action_name="CDK_Build",
                            project=cdk_build,
                            input=source_output,
                            outputs=[cdk_build_output])
                        ]),
                codepipeline.StageProps(stage_name="Deploy",
                    actions=[
                        codepipeline_actions.CloudFormationCreateUpdateStackAction(
                            stack_name="ApplicationStack",
                            action_name="Lambda_CFN_Deploy",
                            template_path=cdk_build_output.at_path(
                                "ApplicationStack.template.json"),
                            admin_permissions=True,
                            replace_on_failure=False,
                        )])
                ]
            )

What did you expect to happen?

The codepipeline deploy action should have succeeded.

What actually happened?

I got the error "Action Execution Failed"

Parameters: [AssetParametersfca855f9f50a848d83797616810eea0f1cd02ba79f05413ce0e5f62e06f17cf6S3Bucket09CDBB21, AssetParameters56c7c06978feac4502fe2beda2acf9baef368d8f873d75fba23650d7c1f9d584S3VersionKey84041DFA, AssetParameters27b58c1b3f137723c1cdbb881058a4b21230873b55318044de2a913e607a49f9S3Bucket8795CE3D, AssetParametersfca855f9f50a848d83797616810eea0f1cd02ba79f05413ce0e5f62e06f17cf6S3VersionKeyDE6051C9, AssetParameters7b8f901e53744758131669f2606b340cd2b32759fbbfc3dd93fb3fa4d08d690aArtifactHash84962CBE, AssetParameters27b58c1b3f137723c1cdbb881058a4b21230873b55318044de2a913e607a49f9ArtifactHash8DB7EB35, AssetParametersfab59f4d2c79000303d9b8e40b25a1922175713a071e3bbd1ab6e381a27e46ecS3VersionKeyE828175E, AssetParameters7b8f901e53744758131669f2606b340cd2b32759fbbfc3dd93fb3fa4d08d690aS3Bucket24A39C33, AssetParameters27b58c1b3f137723c1cdbb881058a4b21230873b55318044de2a913e607a49f9S3VersionKeyFC482B2A, AssetParameters56c7c06978feac4502fe2beda2acf9baef368d8f873d75fba23650d7c1f9d584S3BucketE57AA5E6, AssetParameters7b8f901e53744758131669f2606b340cd2b32759fbbfc3dd93fb3fa4d08d690aS3VersionKey0E38F1A8, AssetParametersfab59f4d2c79000303d9b8e40b25a1922175713a071e3bbd1ab6e381a27e46ecS3BucketA5CBA83A, AssetParametersfca855f9f50a848d83797616810eea0f1cd02ba79f05413ce0e5f62e06f17cf6ArtifactHashEBFB3E6C, AssetParameters56c7c06978feac4502fe2beda2acf9baef368d8f873d75fba23650d7c1f9d584ArtifactHashD99A1DE8, AssetParametersfab59f4d2c79000303d9b8e40b25a1922175713a071e3bbd1ab6e381a27e46ecArtifactHash0431120F] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 890a4f18-9d9d-4576-abf0-cd127ed90c95)

Environment

  • CLI Version : 1.60.0 (build 8e3f53a)
  • Framework Version:
  • Node.js Version: v12.16.1
  • OS : Ubuntu
  • Language (Version): Python3.8

Other

My ApplicationStack contains a lambda function with multiple layers.


This is 🐛 Bug Report

@jonathan-kosgei jonathan-kosgei added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 22, 2020
@jonathan-kosgei jonathan-kosgei changed the title [aws_codepipeline_actions] CloudFormationCreateUpdateStackAction action on cdk synth output fails [aws_codepipeline_actions] CloudFormationCreateUpdateStackAction action with cdk synth output fails Aug 22, 2020
@skinny85
Copy link
Contributor

Hi @jonathan-kosgei ,

can you please show the code for ApplicationStack?

Thanks,
Adam

@skinny85 skinny85 added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 31, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Aug 31, 2020
@github-actions
Copy link

github-actions bot commented Sep 8, 2020

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 8, 2020
@jonathan-kosgei
Copy link
Author

Hi @skinny85 sorry for the delayed response was out of office. Here is the ApplicationStack

from aws_cdk import (
    core,
    aws_s3 as s3,
    aws_logs as logs,
    aws_lambda as lambda_,
)

class ApplicationStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, stage="dev", **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        data_bucket = f"data-{self.region}-{stage}"

        self._data_bucket = s3.Bucket(self, "data-bucket",
            bucket_name=data_bucket,
        )

        data_layer = lambda_.LayerVersion(self, "data-layer",
            layer_version_name=f"data-layer-{stage}",
            code=lambda_.Code.from_bucket(self._data_bucket, "data.zip"),
            compatible_runtimes=[lambda_.Runtime.PYTHON_3_8],
        )

        lambda_function = lambda_.Function(self,'Lambda',
            function_name = f"lambda-{stage}",
            handler='handler.lambda_handler',
            runtime=lambda_.Runtime.PYTHON_3_8,
            code=lambda_.Code.asset('code/'),
            log_retention=logs.RetentionDays.ONE_DAY,
            timeout=core.Duration.seconds(5),
            memory_size=512,
            layers=[data_layer],
        )

@skinny85
Copy link
Contributor

skinny85 commented Oct 1, 2020

Hello @jonathan-kosgei ,

so the problem in your code is clear; it's this line:

            code=lambda_.Code.asset('code/'),

The code in the tutorial you linked uses:

    self.lambda_code = lambda_.Code.from_cfn_parameters()

BTW, I would encourage you to check out the CDK Pipelines module: https://docs.aws.amazon.com/cdk/api/latest/docs/pipelines-readme.html . It offers a better experience for deploying Lambdas that use Assets (like yours does) than that tutorial.

Thanks,
Adam

@jonathan-kosgei
Copy link
Author

jonathan-kosgei commented Oct 2, 2020

Thanks @skinny85 . I was able to make progress with the CDK pipelines module.

I however quickly ran into this issue #9917 when deploying to multiple regions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline-actions bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants