question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot resolve the correct AWS Region locally.

See original GitHub issue

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

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

  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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JadenSimoncommented, Dec 20, 2021

Can confirm that AWS::Region is resolved to ‘us-east-1’ when local debugging despite setting a region and profile in the aws section. A minimal test case is to ref the region apart of an environment variable:

    Environment:
      Variables:
        MY-REGION: !Ref AWS::Region

Also, buildArguments/localArguments should be passed in without delimiters:

      "buildArguments": [
          "--region", "eu-west-1"
      ],
      "localArguments": [
          "--region", "eu-west-1"
      ]

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 aws parameters 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.

1reaction
JadenSimoncommented, Dec 16, 2021

Hey @kunal-stagepilot ,

Looks like this may be two separate bugs. I’ll see what I can replicate on my end and report back.

I can copy/paste and run the command above in terminal and it builds without any issues. It builds successfully.

Now that is interesting. I’m wondering if the toolkit is doing something that causes --region to become an invalid option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set up AWS Credentials and Region for Development
Set the AWS Region in the AWS config file on your local system, located at: ~/.aws/config on Linux, macOS, or Unix. C:\Users\USERNAME\.aws\config on...
Read more >
Configure the AWS Region - AWS SDK for .NET
AWS Regions allow you to access AWS services that physically reside in a specific geographic region. This can be useful for redundancy and...
Read more >
Resolve the IAM Error "AWS was not able to validate the ...
I assumed an AWS Identity and Access Management (IAM) role and my API call returned an error similar to the following:.
Read more >
Resolve problems connecting to an Amazon RDS DB instance
There are a number of root causes for the inability to connect to an Amazon RDS DB instance. Here are a few of...
Read more >
Regions and Zones - Amazon Elastic Compute Cloud
In the upper-right corner of the page, choose Account attributes, Zones. To find your Local Zones using the AWS CLI. Use the describe-availability-zones...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found