question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[assets] cdk synth should package assets in s3 bucket and synthesized template references those assets

See original GitHub issue

CFN & SAM as set a precedence in how people deploy their infrastructure in the cloud. We package the artifacts, a template is returned that references the packaged artifacts and it ready for deploy.

The CDK can follow a similar approach. This makes it easier and less complex in working with serverless applications that have many lambda functions.

Use Case

Many applications take a serverless microservice approach. Where you will have a service with many lambda functions. Currently, the way that it is handled in the cdk is complicated and brittle at the moment.

eg.

export class SomeMicroserviceStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props: SomeMicroserviceStackProps) {

    public readonly lambdaCode1: CfnParametersCode; 
    public readonly lambdaCode2: CfnParametersCode; 
    // n number of readonly properties with reference to lambda functions in microservice

    super(scope, id, props);
          // multi lambda functions
    }
}

Then we have the pipeline

export class PipelineStack extends Stack {
    constructor(scope: cdk.App, id: string, props: PipelineStackProps) {
        super(scope, id, props);

        const paymentServiceDevDeployAction = new CloudFormationCreateUpdateStackAction({

            actionName: "PaymentServiceStack_DEV_Deploy",
            templatePath: servicesBuildOutput.atPath(
            "SomeMicroserviceStack.template.json"),
            stackName: "SomeMicroserviceStack",
            adminPermissions: true,
            account,
            region,
            parameterOverrides: {
            ...props.lambdaCode1.assign(lambda1Output.s3Location),
            ...props.lambdaCode2.assign(lambda2.s3Location),
            // n number of lambdas
            // limit of 1KB
            // For every new lambda function it gets added which becomes a pain
            },
            extraInputs: [lambda1Output, lambda2, .....],
        });
    }
}

Proposed Solution

I believe its more straight forward to have the cdk package the artifact in a user defined bucket and out put to us a parsed template where the artifacts are referenced.

I am taking the concept from SAM. Where we have the command: sam package --template-file PATH --s3-bucket TEXT

so for cdk we would have cdk synth/package [Stack] --s3-bucket TEXT

The output from that command can be used to do a deploy directly or be used in a ci/cd workflow.

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:23 (15 by maintainers)

github_iconTop GitHub Comments

4reactions
shivlakscommented, Jul 14, 2020

@eladb I like the idea of adding cdk package as well outside of synth. I’m not sure if @rix0rrr had any other ideas / thoughts

4reactions
eladbcommented, Jul 9, 2020

We should be able to provide a way to package assets and upload them now that we’ve decoupled assets from deployment into a new tool called cdk-assets.

I am not opposed to adding cdk package which will synthesize the template and run cdk-assets to bundle and publish assets to their needed location.

At any rate, this is a separate step from synth.

Copy @rix0rrr

Reassigning to @shivlaks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets - AWS Cloud Development Kit (AWS CDK) v2
Assets are local files, directories, or Docker images that can be bundled into AWS CDK libraries and apps. For example, an asset might...
Read more >
aws-cdk-lib - npm
The synthesizer controls aspects like: How does the stack reference assets? (Either through CloudFormation parameters the CLI supplies, or ...
Read more >
Assets - CDK for Terraform - HashiCorp Developer
Asset constructs manage assets for resources that need them, such as template_file, S3 bucket objects, or Lambda function archive files.
Read more >
@aws-cdk/aws-s3-assets | Yarn - Package Manager
Furthermore, the synthesized CloudFormation template will also include two CloudFormation parameters: one for the asset's bucket and one for the asset S3 key....
Read more >
My Study Notes on AWS Cloud Development Kit (AWS CDK)
When using the AWS CDK, you must also consider the limitations of AWS ... cdk synth (Synthesizing an AWS CloudFormation Template.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found