[assets] cdk synth should package assets in s3 bucket and synthesized template references those assets
See original GitHub issueCFN & 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:
- Created 3 years ago
- Reactions:9
- Comments:23 (15 by maintainers)
Top GitHub Comments
@eladb I like the idea of adding
cdk package
as well outside of synth. I’m not sure if @rix0rrr had any other ideas / thoughtsWe 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 runcdk-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