(appsync): Appsync with NodejsFunction lambda resolver doesn't work with ESM format
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### What is the problem?
I have an Appsync API with a lambda resolver in nodejs, created with the NodejsFunction function. When changing the bundling option to `format: OutputFormat.ESM` I see the following error in the Appsync logs:
`"error": {
"message": "index.main is undefined or not exported",
"type": "Runtime.HandlerNotFound"
},`
When I remove the format option, everything is working fine again.
### Reproduction Steps
1. Create a GraphqlApi
2. Create a lambda function with NodejsFunction and set the bundling option `format: OutputFormat.ESM`
3. Add the lambda function as a resolver.
### What did you expect to happen?
Appsync executes the queries without any errors just like when the format option wasn't set
### What actually happened?
Got the following error:
`"error": {
"message": "index.main is undefined or not exported",
"type": "Runtime.HandlerNotFound"
},`
### CDK CLI Version
2.15.0 (build 151055e)
### Framework Version
_No response_
### Node.js Version
14
### OS
macOS 12.1
### Language
Typescript
### Language Version
_No response_
### Other information
_No response_
Contributor guide
Research direction
Start by reproducing the GraphqlApi and NodejsFunction setup with bundling format OutputFormat.ESM on Node.js 14, then inspect the generated handler and the AppSync error. Done means AppSync executes resolver queries without the Runtime.HandlerNotFound error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, nodejs, typescript
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100