aws-sam-cli
aws-sam-cli copied to clipboard
Bug: Official example for CDK is not working
Description:
following this example from AWS docs and could not get it working https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-cdk-getting-started.html
Steps to reproduce:
- created repo structure follow guideline here: https://github.com/bobbui/aws-sam-cdk-example
- run commands:
cdk synth --no-staging
sam local invoke MyFunction --no-event -t ./cdk.out/CdkSamExampleStack.template.json
Observed result:
PS F:\work\cdk-sam-example> sam local invoke MyFunction --no-event -t ./cdk.out/CdkSamExampleStack.template.json
Invoking app.lambda_handler (python3.9)
Local image is up-to-date
Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.
Mounting F:\work\cdk-sam-example\my_function as /var/task:ro,delegated, inside runtime container
START RequestId: 47433666-75a8-4458-9623-7b6a5366afd9 Version: $LATEST
LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html
[ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'app'
Traceback (most recent call last):
END RequestId: 2f35111b-8d0d-4f29-8817-c4579ad9a78d
REPORT RequestId: 2f35111b-8d0d-4f29-8817-c4579ad9a78d Init Duration: 0.62 ms Duration: 96.67 ms Billed Duration: 97 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"errorMessage": "Unable to import module 'app': No module named 'app'", "errorType": "Runtime.ImportModuleError", "requestId": "2f35111b-8d0d-4f29-8817-c4579ad9a78d", "stackTrace": []}
Expected result:
Should print out hello world as indicated in the example
Invoking app.lambda_handler (python3.9)
START RequestId: 5434c093-7182-4012-9b06-635011cac4f2 Version: $LATEST
"Hello from SAM and the CDK!"
END RequestId: 5434c093-7182-4012-9b06-635011cac4f2
REPORT RequestId: 5434c093-7182-4012-9b06-635011cac4f2 Init Duration: 0.32 ms Duration: 177.47 ms Billed Duration: 178 ms Memory Size: 128 MB Max Memory Used: 128 MB
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 11
-
sam --version
: 1.121.0 - AWS region: eu-central-1
# Paste the output of `sam --info` here
{
"version": "1.121.0",
"system": {
"python": "3.11.8",
"os": "Windows-10-10.0.22631-SP0"
},
"additional_dependencies": {
"docker_engine": "26.1.3",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
Add --debug flag to command you are running