aws / aws/aws-sam-cli

Ref resolves resource identifier rather than DynamoDB table name

Open
#1,604 6 comments 5 reactions 0 assignees View on GitHub
area/intrinsics type/feature
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

There seem to be a few closed issues about intrinsics, but they were closed after a new feature release. Hopefully this isn't a duplicate.

### Description

I'm using a Cloudformation template generated by CDK. I want to pass a DynamoDB table's name to my Lambda by environment variable, however it is resolving the resource identifier when using `sam local start-api`.

### Steps to reproduce

1. Clone this repository: https://github.com/charlocharlie/aws-sam-repro.git
2. `npm i`
3. Run `./sam.sh`
4. Open http://localhost:3000/ in your browser
5. Observe results in console

### Observed result

```
Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
local start-api command is called
Collected default values for parameters: {}
12 resources found in the template
Found Lambda function with name='Handler886CB40B' and CodeUri='/Users/abc/projects/aws-sam-repro/lambda/dist'
Collected default values for parameters: {}
12 resources found in the template
Skipping resource 'APIGateway71B6BBE0'. Swagger document not found in Body and BodyS3Location
Extracted Function ARN: arn:aws:lambda:us-east-1:123456789012:function:Handler886CB40B
1 APIs found in the template
Mounting Handler886CB40B at http://127.0.0.1:3000/ [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
Localhost server is starting up. Multi-threading = True
2019-11-26 08:39:24 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Constructed String representation of Event to invoke Lambda. Event: {"httpMethod": "GET", "body": null, "resource": "/", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "PostmanRuntime/7.19.0", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "497db211-fb60-4290-ac82-80efe7818257", "Host": "localhost:3000", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"User-Agent": ["PostmanRuntime/7.19.0"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["497db211-fb60-4290-ac82-80efe7818257"], "Host": ["localhost:3000"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/", "isBase64Encoded": false}
Found one Lambda function with name 'Handler886CB40B'
Invoking handler.handler (nodejs12.x)
Environment variables overrides data is in CloudFormation parameter file format
Loading AWS credentials from session with profile 'None'
Resolving code path. Cwd=/Users/abc/projects/aws-sam-repro, CodeUri=/Users/abc/projects/aws-sam-repro/lambda/dist
Resolved absolute path to code is /Users/abc/projects/aws-sam-repro/lambda/dist
Code /Users/abc/projects/aws-sam-repro/lambda/dist is not a zip/jar file
Skipping building an image since no layers were defined

Fetching lambci/lambda:nodejs12.x Docker container image......
Mounting /Users/abc/projects/aws-sam-repro/lambda/dist as /var/task:ro,delegated inside runtime container
Starting a timer for 3 seconds for function 'Handler886CB40B'
START RequestId: 0fbaf43f-0b88-1148-42ef-b92daf428832 Version: $LATEST
2019-11-26T14:39:31.681Z 0fbaf43f-0b88-1148-42ef-b92daf428832 INFO ENV_VARS: {
AWS_LAMBDA_FUNCTION_VERSION: '$LATEST',
HOSTNAME: 'f19ded1a18e3',
_LAMBDA_CONTROL_SOCKET: '14',
AWS_SAM_LOCAL: 'true',
AWS_LAMBDA_FUNCTION_TIMEOUT: '3',
AWS_LAMBDA_LOG_GROUP_NAME: '/aws/lambda/test',
LAMBDA_TASK_ROOT: '/var/task',
LD_LIBRARY_PATH: '/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib',
AWS_LAMBDA_RUNTIME_API: '127.0.0.1:9001',
AWS_LAMBDA_LOG_STREAM_NAME: '2019/11/26/[$LATEST]193083bacd76fabef2b4e3d8f3acff8b',
_LAMBDA_SHARED_MEM_FD: '11',
AWS_EXECUTION_ENV: 'AWS_Lambda_nodejs12.x',
_LAMBDA_RUNTIME_LOAD_TIME: '1530232235231',
AWS_LAMBDA_FUNCTION_NAME: 'test',
AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2:2000',
PATH: '/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin',
_LAMBDA_LOG_FD: '9',
TABLE_NAME: 'TableCD117FA1',
TEST_VAR_TEMPLATE: 'TEST',
AWS_DEFAULT_REGION: 'us-east-1',
PWD: '/var/task',
AWS_SECRET_ACCESS_KEY: 'defaultsecret',
LAMBDA_RUNTIME_DIR: '/var/runtime',
LANG: 'en_US.UTF-8',
NODE_PATH: '/opt/nodejs/node12/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules',
TZ: ':UTC',
AWS_REGION: 'us-east-1',
AWS_LAMBDA_FUNCTION_HANDLER: 'handler.handler',
AWS_ACCESS_KEY_ID: 'defaultkey',
SHLVL: '0',
HOME: '/home/sbx_user1051',
_AWS_XRAY_DAEMON_ADDRESS: '169.254.79.2',
_AWS_XRAY_DAEMON_PORT: '2000',
_X_AMZN_TRACE_ID: 'Root=1-dc99d00f-c079a84d433534434534ef0d;Parent=91ed514f1e5c03b2;Sampled=1',
_LAMBDA_SB_ID: '7',
AWS_XRAY_CONTEXT_MISSING: 'LOG_ERROR',
_LAMBDA_CONSOLE_SOCKET: '16',
_HANDLER: 'handler.handler',
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: '128',
AWS_LAMBDA_EVENT_BODY: '{"httpMethod": "GET", "body": null, "resource": "/", "requestContext": {"resourceId": "123456", "apiId": "1234567890", "resourcePath": "/", "httpMethod": "GET", "requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", "accountId": "123456789012", "stage": "prod", "identity": {"apiKey": null, "userArn": null, "cognitoAuthenticationType": null, "caller": null, "userAgent": "Custom User Agent String", "user": null, "cognitoIdentityPoolId": null, "cognitoAuthenticationProvider": null, "sourceIp": "127.0.0.1", "accountId": null}, "extendedRequestId": null, "path": "/"}, "queryStringParameters": null, "multiValueQueryStringParameters": null, "headers": {"User-Agent": "PostmanRuntime/7.19.0", "Accept": "*/*", "Cache-Control": "no-cache", "Postman-Token": "497db211-fb60-4290-ac82-80efe7818257", "Host": "localhost:3000", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "X-Forwarded-Proto": "http", "X-Forwarded-Port": "3000"}, "multiValueHeaders": {"User-Agent": ["PostmanRuntime/7.19.0"], "Accept": ["*/*"], "Cache-Control": ["no-cache"], "Postman-Token": ["497db211-fb60-4290-ac82-80efe7818257"], "Host": ["localhost:3000"], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "X-Forwarded-Proto": ["http"], "X-Forwarded-Port": ["3000"]}, "pathParameters": null, "stageVariables": null, "path": "/", "isBase64Encoded": false}'
}
END RequestId: 0fbaf43f-0b88-1148-42ef-b92daf428832
REPORT RequestId: 0fbaf43f-0b88-1148-42ef-b92daf428832 Init Duration: 695.26 ms Duration: 22.90 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 39 MB
No Content-Type given. Defaulting to 'application/json'.
2019-11-26 08:39:32 127.0.0.1 - - [26/Nov/2019 08:39:32] "GET / HTTP/1.1" 200 -
```

### Expected result

The environment variable `TABLE_NAME` should be `my-table-name`. This is what is observed when deployed to Cloudformation.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: MacOS 10.14.6
2. `sam --version`: 0.33.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.