aws / aws/aws-sam-cli

sam local invoke produces invalid ARNs for step functions using the GetAtt function

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

Description

### Description:

When using `sam local invoke` to run a Lambda locally, the `GetAtt` function is substituting an invalid ARN into an environment variable within the Lambda. It should be using a state machine ARN but is formatting it like a Lambda ARN.

When I deploy this using `sam deploy` the ARN in the environment variables for the Lambda is substituted correctly. Therefore, I believe this is a bug with the SAM CLI. Can anyone recreate this issue?

### Steps to reproduce:

**SAM CLI Version:** 1.19.1
**Template File:** `template.yaml`:
```yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
Test-Template

Resources:
TestFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/lambda
Handler: test-function.lambdaHandler
Runtime: nodejs14.x
Environment:
Variables:
STEPFUNCTION_ARN: !GetAtt MyStepFunction.Arn

MyStepFunction:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: statemachine/my-step-function.asl.json
Policies:
- LambdaInvokePolicy:
FunctionName: "*Someotherfunctions"
```

**Lambda Definition**`test-function.js`:
```js
exports.lambdaHandler = () => console.info(process.env.STEPFUNCTION_ARN);
```

### Observed result:

```sh
$ sam local invoke --region eu-west-1 TestFunction
2021-03-24T13:02:38.017Z 62581b08-94a5-49e2-a952-58413ba7653e INFO arn:aws:lambda:eu-west-1:123456789012:function:MyStepFunction
```

### Expected result:

The expected output would be an ARN which was a valid step function ARN. Something like:
```
arn:aws:states:eu-west-1:123456789012:stateMachine:MyStepFunction
```

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

1. OS: Mac OS Catalina
2. `sam --version`: 1.19.1
3. AWS region: eu-west-1

`Add --debug flag to command you are running`
```
2021-03-24 13:40:47,534 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-03-24 13:40:47,535 | local invoke command is called
2021-03-24 13:40:47,538 | No Parameters detected in the template
2021-03-24 13:40:47,561 | 2 resources found in the stack
2021-03-24 13:40:47,561 | No Parameters detected in the template
2021-03-24 13:40:47,594 | No Parameters detected in the template
2021-03-24 13:40:47,615 | Found Serverless function with name='TestFunction' and CodeUri='src/lambda'
2021-03-24 13:40:47,625 | Found one Lambda function with name 'TestFunction'
2021-03-24 13:40:47,625 | Invoking test-function.lambdaHandler (nodejs14.x)
2021-03-24 13:40:47,625 | Environment variables overrides data is standard format
2021-03-24 13:40:47,625 | Loading AWS credentials from session with profile 'None'
2021-03-24 13:40:49,648 | Resolving code path. Cwd=/Users/tobydickinson/repos/sam-test, CodeUri=/Users/tobydickinson/repos/sam-test/src/lambda
2021-03-24 13:40:49,648 | Resolved absolute path to code is /Users/tobydickinson/repos/sam-test/src/lambda
2021-03-24 13:40:49,649 | Code /Users/tobydickinson/repos/sam-test/src/lambda is not a zip/jar file
2021-03-24 13:40:49,670 | Skip pulling image and use local one: amazon/aws-sam-cli-emulation-image-nodejs14.x:rapid-1.19.1.

2021-03-24 13:40:49,670 | Mounting /Users/tobydickinson/repos/sam-test/src/lambda as /var/task:ro,delegated inside runtime container
2021-03-24 13:40:50,052 | Starting a timer for 3 seconds for function 'TestFunction'
START RequestId: 222f03f9-081a-40d2-9109-6b52f2862495 Version: $LATEST
2021-03-24T13:40:50.193Z 222f03f9-081a-40d2-9109-6b52f2862495 INFO arn:aws:lambda:eu-west-1:123456789012:function:MyStepFunction
END RequestId: 222f03f9-081a-40d2-9109-6b52f2862495
REPORT RequestId: 222f03f9-081a-40d2-9109-6b52f2862495 Init Duration: 0.19 ms Duration: 128.25 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 128 MB
2021-03-24 13:40:50,364 | Cleaning all decompressed code dirs
2021-03-24 13:40:50,365 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'b52ff91a-cf44-4eed-a8e7-9b2b2f7bb41f', 'installationId': '7dc14e3c-579d-4bfd-b043-b629abcb0afc', 'sessionId': 'b1b2cfcc-c750-4f09-9dff-f6a53b535cf8', 'executionEnvironment': 'CLI', 'pyversion': '3.8.8', 'samcliVersion': '1.19.1', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': 'eu-west-1', 'commandName': 'sam local invoke', 'duration': 2830, 'exitReason': 'success', 'exitCode': 0}}]}
2021-03-24 13:40:50,964 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
null2021-03-24 13:40:50,964 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2021-03-24 13:40:50,964 | Sending Telemetry: {'metrics': [{'runtimeMetric': {'requestId': '3b87cdeb-16be-4880-88aa-506bc905a37b', 'installationId': '7dc14e3c-579d-4bfd-b043-b629abcb0afc', 'sessionId': 'b1b2cfcc-c750-4f09-9dff-f6a53b535cf8', 'executionEnvironment': 'CLI', 'pyversion': '3.8.8', 'samcliVersion': '1.19.1', 'runtimes': ['nodejs14.x']}}]}
2021-03-24 13:40:51,513 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.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.