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

typescript - api-cors-lambda-crud-dynamodb -missing uuid in package.json #276

Closed
nazreen opened this issue Apr 23, 2020 · 13 comments · Fixed by #468
Closed

typescript - api-cors-lambda-crud-dynamodb -missing uuid in package.json #276

nazreen opened this issue Apr 23, 2020 · 13 comments · Fixed by #468
Assignees
Labels
bug This issue is a bug. dependencies This issue is a problem in a dependency or a pull request that updates a dependency file. effort/medium Medium work item – a couple days of effort in-progress Issue is being actively worked on. language/typescript Related to Typescript examples p1

Comments

@nazreen
Copy link

nazreen commented Apr 23, 2020

🐛 Bug Report

What is the problem?

Error message Error: Cannot find module 'uuid/v4 when testing create function.

Reproduction Steps

  1. deploy the stack as per instructions
  2. go to the AWS Console and test createItem function with the following test event:
{
  "body": "{\"data\":{\"name\":\"foo\"}}"
}
  1. The result will be that the task timed out. Go to Cloudwatch and view the log for the function. It will complain this: "Error: Cannot find module 'uuid/v4

Environment

  • CDK CLI Version: 1.34.1
  • Example: api-cors-lambda-crud-dynamodb
  • Example Version: createItem function
  • OS: OSX Catalina
  • Language: Typescript

Other information

The solution requires the uuid package being present inside a node_modules of the src folder. Currently there is no package.json inside the src folder.

@nazreen nazreen added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 23, 2020
@hossain-rayhan
Copy link

Hi @nazreen , thanks for creating the issue. I was able to reproduce it. Will update once I finish testing your PR.

@nazreen
Copy link
Author

nazreen commented Apr 23, 2020

hi @hossain-rayhan , I realised my PR was wrong. I am going to update it now.

@nazreen
Copy link
Author

nazreen commented Apr 23, 2020

@hossain-rayhan I have updated the issue description with more detail on the error and the solution. I will submit a PR with the fix now.

@nazreen
Copy link
Author

nazreen commented Apr 23, 2020

ok so the fix to this issue is in #278

@SomayaB SomayaB added the in-progress Issue is being actively worked on. label Apr 24, 2020
@SomayaB SomayaB added the language/typescript Related to Typescript examples label Apr 24, 2020
@NGL321 NGL321 added dependencies This issue is a problem in a dependency or a pull request that updates a dependency file. p1 and removed needs-triage This issue or PR still needs to be triaged. labels May 8, 2020
@NGL321
Copy link
Contributor

NGL321 commented May 8, 2020

Hey @nazreen, I apologize for the delay in response!

It appears that the issue is not the package.json but that the uuid package actually introduced a breaking change to the way it handles imports. You can see the issue was also experienced with just lambda.

Thank you for working on this!

😷

@nazreen
Copy link
Author

nazreen commented May 8, 2020

@NGL321 ,

ok, so I tried updating the line to:
const { v4: uuidv4 } = require('uuid'); per the latest instruction from the npm page, the new error is "Error: Cannot find module 'uuid'"

correct me if I'm wrong, but uuid is not a built-in node module, so it has to be installed via npm anyways right?

@NGL321
Copy link
Contributor

NGL321 commented May 8, 2020

@nazreen After verification, you are correct. Actually, in hindsight, I am surprised this worked to begin with 🤷.

The proper solution to this would be to utilize a Lambda Layer, however the solution proposed here of zipping the whole lambda with dependencies as a single deployment package is also valid.

There are really two options for this. Either pre-package and update the example with that package, or add instructions on building out that package.
I understand this is more work than you initially signed up for, but if you still want to add this, please feel free to @ me in another PR!

Cheers
😸 😷

@nazreen
Copy link
Author

nazreen commented May 8, 2020

@NGL321 thanks for the quick response! Going to write this now before I go to bed (will continue tomorrow). I'd like to see this through, don't worry!

Okay, so the deployment package approach, is the approach in this PR. AFAIK, cdk's lambda.AssetCode() will bundle the specified directory. All its contents will be uploaded as the lambda code, in this case, including the node_modules folder.

However, I think there's a complication that you might be able to shed light on. The build fails. The error message is --app is required either in command-line, in cdk.json or in ~/.cdk.json

I think this is because for every package.json, there's a check for an adjacent cdk.json. So since the package.json inside src doesn't, the error throws. Is this accurate? I'm not sure, just a guess.

@nazreen
Copy link
Author

nazreen commented May 13, 2020

@NGL321 bump :) just checking if you're aware of this

@stilren
Copy link

stilren commented Jun 30, 2020

Anyway we could get a fix for this? Would be good with an example showing how to do external dependencies with ts cdk

@sachin10101998
Copy link

Any fix available for this yet?

@chrischenyc
Copy link

I think using the experimental @aws-cdk/aws-lambda-nodejs is the way to go, works for me:

https://github.com/chrischenyc/url-shortener-cdk-typescript

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. dependencies This issue is a problem in a dependency or a pull request that updates a dependency file. effort/medium Medium work item – a couple days of effort in-progress Issue is being actively worked on. language/typescript Related to Typescript examples p1
Projects
None yet
7 participants