Cannot resolve the correct AWS Region locally.
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 807
- Avg merge
- 10h 12m
- Merged PRs (30d)
- 7
Description
**Describe the bug**
${AWS::Region} always resolved to us-east-1 when debugging SAM application locally via VS Code AWS Toolkit.
My lambda function has a layer
```YAML
Layers:
- !Sub "arn:aws:lambda:${AWS::Region}:898466741470:layer:psycopg2-py38:1"
```
While this works when I deploy my application stack to my AWS instance, it incorrectly resolves the region to us-east-1 when I debug locally.
My default profile region is set to eu-west-1.
I added this to my debug configuration file, but ${AWS::Region} still resolved to us-east-1
```JSON
"aws": {
"credentials": "profile:default",
"region": "eu-west-1"
},
```
Next, I tried adding `buildArguments` and `localArguments` to the debug config file:
```JSON
"sam": {
"containerBuild": false,
"skipNewImageCheck": false,
"buildArguments": [
"--region eu-west-1"
],
"localArguments": [
"--region eu-west-1"
]
},
```
When debugging, I get this error `Error: no such option: --region eu-west-1`
It fails on this command:
Note: I've truncated paths for brevity
```bash
2021-12-16 12:45:33 [INFO]: Running command: (not started) [(path to sam)\sam.cmd build --build-dir (user path)\aws-toolkit-vscode\vsctk6pwmOB\output --template (repo path)/virtual-events-admin/template.yaml --manifest (user path)\aws-toolkit-vscode\vsctk6pwmOB\debug-requirements.txt --region eu-west-1]
```
_I can copy/paste and run the command above in terminal and it builds without any issues. It builds successfully._
**To Reproduce**
1. In your SAM template, include an resource ARN which contains ${AWS::Region}.
2. Debug the SAM application locally, you will notice ${AWS::Region} resolves to us-east-1 regardless of which region you set.
**Expected behavior**
1. ${AWS::Region} should resolve to the region set `aws`/`region` key in the SAM debug config file.
2. If region build or local arguments are included, in the SAM debug config file, local debugging shouldn't throw an error
**Computer (please complete the following information):**
- Windows Version: Windows 10 Pro (21H1)
- Visual Studio Version: Visual Studio Code (1.63.0)
- AWS Toolkit for Visual Studio Version: v1.34.0
Contributor guide
Research direction
Start with the SAM debug configuration, template.yaml, and the logged `sam.cmd build` invocation, comparing how the `aws.region`, `buildArguments`, and `localArguments` settings are passed during local debugging. Done means `${AWS::Region}` uses the configured region and region arguments do not cause local debugging to fail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100