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

AWS SAM CLI beta CDK build cannot invoke Lambda functions generated by AWS Solutions Constructs #228

Closed
alexpulver opened this issue Jun 20, 2021 · 1 comment · Fixed by #260
Assignees
Labels
bug Something isn't working

Comments

@alexpulver
Copy link

AWS SAM CLI beta CDK build cannot invoke Lambda function generated by aws_solutions_constructs.aws_apigateway_lambda.ApiGatewayToLambda construct.

Reproduction Steps

  1. Install AWS SAM CLI beta CDK build following the instructions in Getting started with AWS SAM and the AWS CDK

  2. Run the following commands:

git clone https://github.com/alexpulver/aws-cdk-project-structure-python-basic
cd aws-cdk-project-structure-python-basic

# *** Remove "@aws-cdk/core:newStyleStackSynthesis": "true" from cdk.context.json ***

python3 -m venv .venv
source .venv/bin/activate
./install-deps.sh
export AWS_ACCESS_KEY_ID="****"
export AWS_SECRET_ACCESS_KEY="****"
export AWS_SESSION_TOKEN="****"
npx cdk synth
grep -B1 ::Function cdk.out/AwsCdkProjectDev.template.json 
# Example output:
#    "ApiApiGatewayToLambdaLambdaFunction036A2BFE": {
#      "Type": "AWS::Lambda::Function",
sam-beta-cdk local invoke AwsCdkProjectDev/ApiApiGatewayToLambdaLambdaFunction036A2BFE

Error Log

The resource AWS::Lambda::Function 'ApiApiGatewayToLambdaLambdaFunction036A2BFE' has specified S3 location for Code. It will not be built and SAM CLI does not support invoking it locally.
The resource AWS::Lambda::Function 'ApiApiGatewayToLambdaLambdaFunction036A2BFE' has specified S3 location for Code. It will not be built and SAM CLI does not support invoking it locally.
AwsCdkProjectDev/ApiApiGatewayToLambdaLambdaFunction036A2BFE not found. Possible options in your template: []
Error: Function AwsCdkProjectDev/ApiApiGatewayToLambdaLambdaFunction036A2BFE not found in template

Environment

  • CDK CLI Version : 1.106.1
  • CDK Framework Version: 1.106.1
  • AWS Solutions Constructs Version : 1.106.1
  • OS : macOS Catalina 10.15.7
  • Language : English

Other

The ApiGatewayToLambda construct overwrites the Metadata field (source code) to add the cfn_nag object. The original CDK Lambda construct populates fields like aws:asset:path and aws:asset:property into the resource Metadata. sam-beta-cdk relies on these info to locate the local Lambda code. I think the ApiGatewayToLambda construct should try to avoid overwriting the whole Metadata object. Instead, it should only update the existing Metadata object. Thanks @hawflau for the analysis!


This is 🐛 Bug Report

@alexpulver alexpulver added bug Something isn't working needs-triage The issue or PR still needs to be triaged labels Jun 20, 2021
@biffgaut biffgaut self-assigned this Jun 21, 2021
@biffgaut biffgaut added in-progress This issue is being actively worked on and removed needs-triage The issue or PR still needs to be triaged labels Jul 12, 2021
@biffgaut biffgaut removed the in-progress This issue is being actively worked on label Jul 12, 2021
@alexpulver
Copy link
Author

@biffgaut thanks a lot! Saw that this was finally released in AWS Solutions Constructs 1.114.0 today, tested with the latest AWS SAM CLI beta and it works.

$ sam-beta-cdk local invoke UUID4GeneratorBackend-Dev/LambdaFunction | jq
Synthesizing CDK App
Invoking app.handler (python3.7)
Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-python3.7:rapid-1.22.0.dev202107140310.

Mounting /Users/apulver/aws-cdk-project-structure-python-basic/.aws-sam/.cdk-out/asset.95125f45dbdf585e631e3e345d6e11e03ba441f7d55587aaf2a22c66392ce5c7 as /var/task:ro,delegated inside runtime container
START RequestId: 12c2925f-9e79-4713-9046-9db3be3c5195 Version: $LATEST
request: {}
END RequestId: 12c2925f-9e79-4713-9046-9db3be3c5195
REPORT RequestId: 12c2925f-9e79-4713-9046-9db3be3c5195	Init Duration: 0.24 ms	Duration: 960.08 ms	Billed Duration: 1000 ms	Memory Size: 128 MB	Max Memory Used: 128 MB	
{
  "statusCode": 200,
  "headers": {
    "Content-Type": "text/plain"
  },
  "body": "Hello, CDK! Here is your UUID4: {'uuid': '32c5e81c-c9b7-48ef-91fb-ac8a9fddafab'}\n"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants