- Newest
- Most votes
- Most comments
The issue you're experiencing with AWS SAM local start-api not being able to resolve Fn::ImportValue is a known limitation when testing CDK applications locally. This occurs because the Fn::ImportValue function is designed to work with deployed CloudFormation stacks, and local testing environments don't have access to these deployed resources.
To address this issue, there are a few approaches you can take:
-
Ensure you're running the latest versions of AWS CDK and AWS SAM CLI. Sometimes, updates to these tools can resolve compatibility issues.
-
Before running any SAM local commands with a CDK application, always run 'cdk synth' first. This ensures that your CloudFormation template is up-to-date with your latest CDK code changes.
-
When using SAM local commands with CDK applications, make sure to specify the path to your synthesized CloudFormation template. For example:
sam local start-api -t ./cdk.out/YourStackName.template.json
-
If your application uses nested stacks, you may need to provide the stack name where the function is defined to resolve naming conflicts.
-
Consider using the 'sam local start-lambda' command instead of 'sam local start-api' if you're primarily testing Lambda functions. This command starts a local endpoint that emulates AWS Lambda and may be less prone to issues with resolving CloudFormation intrinsic functions.
-
As a last resort, if the issue persists, you can try the approach you mentioned: uninstalling and reinstalling CDK globally, recreating the node_modules folder, and deleting the cdk.out folder before running 'cdk synth' again.
While these steps can help mitigate the issue, it's important to note that local testing of CDK applications with SAM has limitations, particularly when it comes to resolving certain CloudFormation functions. For the most accurate testing, consider deploying your application to a test environment in the cloud.
Sources
Locally testing AWS CDK applications with AWS SAM - AWS Serverless Application Model
Introduction to testing with sam local start-lambda - AWS Serverless Application Model
answered 2 years ago
Relevant content
asked 4 years ago
asked 4 years ago
