Cannot resolve the correct AWS Region locally.
See original GitHub issueDescribe 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
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
"aws": {
"credentials": "profile:default",
"region": "eu-west-1"
},
Next, I tried adding buildArguments and localArguments to the debug config file:
"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
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
- In your SAM template, include an resource ARN which contains ${AWS::Region}.
- Debug the SAM application locally, you will notice ${AWS::Region} resolves to us-east-1 regardless of which region you set.
Expected behavior
- ${AWS::Region} should resolve to the region set
aws/regionkey in the SAM debug config file. - 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)

Top Related StackOverflow Question
Can confirm that
AWS::Regionis resolved to ‘us-east-1’ when local debugging despite setting a region and profile in theawssection. A minimal test case is to ref the region apart of an environment variable:Also,
buildArguments/localArgumentsshould be passed in without delimiters:That’s why there was an error. We’re passing in the arguments as-is with no shell. Using the above correctly set my environment variable to ‘eu-west-1’. I didn’t notice this the first read-through since the Toolkit’s output makes it look like the command is correct when it actually isn’t.
Of course, the fact that the
awsparameters don’t do anything is also confusing. It looks like we only use those fields inside the lambda as opposed to invoking SAM CLI. We may need to rethink how this is done since this behavior is clearly counterintuitive.Hey @kunal-stagepilot ,
Looks like this may be two separate bugs. I’ll see what I can replicate on my end and report back.
Now that is interesting. I’m wondering if the toolkit is doing something that causes
--regionto become an invalid option.