-
Notifications
You must be signed in to change notification settings - Fork 7
Troubleshooting Guide
Problem
CDK runs inside a Docker container and spins up new images as cdk synth is used over and over. These images take up space on your device until your device is full
Solution
- Run
docker system pruneto wipe all unused Docker images from your device - Run
cdk synthandsam local start-api -t <template-name>WITHOUT the--skip-pull-imageargument to rebuild the latest SAM Docker image.
Problem
On running cdk deploy, the error Error: not enough values to unpack (expected 2, got 1) is received and the stack fails to deploy.
Solution
This appears to happen when establishing websocket constructs in offline/local mode.
- Run
export IS_OFFLINE=trueto ensure you are running 'offline' locally. - If you must run against a remote environment yet you want to test locally, you may have to look at the stack definition code and comment out wherever websocket constructs are defined. Make sure the comments are removed before pushing to the remote environment.
- If you are creating net new websocket constructs, ensure their definition code is wrapped in a check statement that ignores the websocket in the build phase if
process.env.IS_OFFLINE=true.
Problem
In some cases, particularly when an AWS resource is moved, renamed, or deleted, the cdk synth and cdk deploy actions may fail due to a previously existing resource.
Example: Api Gateway resource path variable was renamed, but the old one cannot be deleted.
Solution
- Go into CloudFormation
- Locate the resource causing the error
- Delete the resource manually
- Redeploy the stack - by re-running the GH Action, for example.
CDK should be smart enough to create a brand new resource with the correct settings.
Problem
When deleting an API Gateway resource, stack deploy fails on occasion such that an API Gateway resource at a particular path will have been created as per the stack in CloudFormation, but no resource exists. Usually when this happens, CloudFormation will list the path for the resource name it is expecting, for example /stage/resourcePath.
Solution
- Go into CloudFormation and collect the expected path for the resource, ie
/stage/resourcePath. - Go into API Gateway and manually recreate the resource
/stage/resourcePath. - Redeploy the stack - by re-running the GH Action, for example.
- If redeploy successful, go back into API Gateway and manually delete the resource
/stage/resourcePath.
There are many places where deploying the API locally can trip up, so here is a general list of troubleshooting strategies that may help solve spurious errors:
- Run
cdk synth && sam local start-api -t <path/to/sam/template>with no other arguments at least once. Many of theyarnshorthand scripts that are included inpackage.jsonignore certain steps that are cumbersome when developing locally, but still need to be run every so often. One example is the argument--skip-pull-image, which is included inyarn start, that tells the script to ignore looking for and downloading the latest SAM Docker image. If this image has not been downloaded previously (the local API has not been run before) or if it has been updated and is now out of date, spurious errors may arise. - Delete
cdk.outand re-runcdk synth.
Problem
When running yarn start and calling and endpoint, the server responds with 502 and the following error:
Failed to calculate the hash of resource <..user/path/reserve-rec-cdk/cdk.out/asset.xxx>Solution
In the past it has been discovered that this error arises when a dependency is missing from asset.xxx. In particular, a dependency that was imported in the function code of a layer was not declared in the package.json file in the layer's nodejs folder. Navigating to the nodejs folder and adding the dependency resolved this particular issue.
cd layers/<layer>/nodejs && yarn add <dependency>
It is possible that similar missing reference errors or general compilation errors with the offending asset may cause similar problems.
The cause of this error is spurious but it can be circumvented by removing the --warm-containers LAZY/EAGER argument from sam local start-api (yarn start). This will force a container build every time the function is invoked (not ideal for heavy Lambda Layer use).
See the solutions for general local CDK API errors.