-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
KeyError when running sam-beta-cdk build on projen typescript app #2849
Comments
I was not able to reproduce this issue
|
@moelasmar I believe that might be because you're in the main branch. Could you try switching to the The main branch does not currently create the stack that has the reference to the lambda function. |
ok, thanks for the update |
I can reproduce the issue |
Workaround is to set |
I can confirm and reproduce this in my CDK-SAM python project as well: aws-samples/aws-sam-support-aws-cdk#1 (comment) The workaround suggested by @redbaron seems to work great... I reckon that directive should be included in |
I reproduced this also with TypeScript CDK 2.0.0-rc.11, and TypeScript Lambda function. After changing
Indeed the package.json is missing. There is only index.js file which contains my Lambda code as JavaScript. So dependencies, that package.json, does not get copied/generated? EDIT: EDIT2: Then package.json gets generated but this does not work either. The build then complains about the missing name and version:
And indeed those are missing. I tested this with lambda-log dependency and then package.json looks like this: Proposed fix: optimal solution would to allow totally bundled JavaScript code. Fix could be "empty package.json" generation (if it is missing) after "Synthesizing CDK App" but before running "NodejsNpmBuilder:NpmPack" when running |
This other issue seems related |
Hi, I just ran into this while trying to get SAM and CDK to work. As a workaround I defined the NodejsFunction to copy a dummy package.json after the bundling to the out directory which seems to work. First I created a package.json file containing just the bare minimum: {
"name": "dummy",
"version": "1.0.0"
} For this test I put it into the tests folder that was created by scaffolding. After that I changed the function definition to contain the code that copies the file to the out directory: const helloFunction = new NodejsFunction(this, 'HelloHandler', {
handler: 'lambdaHandler',
entry: 'hello-world/app.js',
bundling: {
commandHooks: {
beforeBundling(inputDir: string, outputDir: string): any {},
afterBundling(inputDir: string, outputDir: string): string[] {
return [`cp ${inputDir}/test/package.json ${outputDir}`];
},
beforeInstall(inputDir: string, outputDir: string): any {}
}
}
}); I admit that's not the prettiest workaround, but it seems to work and running |
Hey all, since AWS SAM CLI now supports CDK differently than in the beta, this issue shouldn't exist anymore since CDK will handle this type of building logic. Please try using the GA version and re-open if a similar problem exists. |
Description:
I have a cdk TypeScript project created using projen. My project contains two stacks, a codepipeline stack and the application stack. In the application stack, I'm creating a lambda resource. When I run
sam-beta-cdk build
, I get the error below:Steps to reproduce:
Install projen and sam-cdk-beta
Create a projen TypeScript app -
projen new awscdk-app-ts
Set
"@aws-cdk/core:newStyleStackSynthesis": true
incdk.json
Create a codepipeline stack in
main.ts
Create an application stack that creates a lambda resource using
code: lambda.Code.fromAsset
, egcode: lambda.Code.fromAsset('lambda')
with the folder lambda placed at the rootCreate your lambda and a package.json file in the lambda folder
Initialize your application stack in the codepipeline stack
Run
sam-beta-cdk build
.You can also just use the repo here : https://github.com/mbuotidem/guichet/tree/sam-beta-cdk
Observed result:
Expected result:
sam-beta-cdk build
should complete without any issues and I should be able to then runsam-cdk-beta local invoke
to test the lambda function locally.Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
sam --version
: SAM CLI, version 1.22.0.dev202104291816The text was updated successfully, but these errors were encountered: