aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

CDK dependencies are not dev dependencies? #9698

Closed mnapoli closed 4 years ago

mnapoli commented 4 years ago

:question: General Issue

The Question

I created a new sample CDK application and noticed that CDK dependencies are installed as production dependencies (not dev dependencies).

That makes me wonder: first, is there a reason for that?

Second, will that not make the deployed Lambda functions much heavier? Out of the box with the sample app I have a 170MB node_modules folder, none of that will be useful on Lambda.

Environment

Other information

hoegertn commented 4 years ago

The dependencies are prod dependencies of the CDK application. CDK is not meant to be seen as your dev tool inside your app but your app is CDK.

Your Lambda functions then use another package.json that defines the deps of your Lambda so CDK will never make it into the Lambda ZIP.

I hope this makes things clearer for you.

mnapoli commented 4 years ago

OK, I think I see what you mean. That means that I should separate the "CDK app" from my actual application, right?

What is the recommended directory layout in that case?

To give you some context, I'm trying to evaluate the AWS CDK for https://github.com/brefphp/bref (which currently uses the serverless framework). I'm struggling a lot with the fact that I'm moving from 1 configuration file (serverless.yml) to a whole project inside my project, with node_modules and everything. I'm trying to find a solution to make this simpler for Bref users.

hoegertn commented 4 years ago

I am not sure if there is an official recommended layout but I am using a folder called lambdas/ that contains my lambda projects.

mnapoli commented 4 years ago

that contains my lambda projects.

OK just to be clear, do you mean the SDK code, or the application code?

A:

index.js
package.json
# lambda code

lambdas/
    index.js
    package.json
    # CDK code

or B:

index.js
package.json
# CDK code

lambdas/
    index.js
    package.json
    # application code
hoegertn commented 4 years ago

Sorry for the confusion. Variant B but I am using TypeScript. For multiple lambdas sometimes I use more subfolders inside the lambda folder and have on package.json per asset or lambda.

mnapoli commented 4 years ago

Thanks!