Skip to content

Toolkit does not explicitly set a region for SAM CLI invokes #416

@bryceitoc9

Description

@bryceitoc9

Describe the bug
SAM invoke calls (via "Run Locally" and "Debug Locally") will fail if a user does not have a [default] entry in their ~/.aws/config file containing a region value.

To Reproduce

  1. Delete/rename/move your ~/.aws/config file
  2. Attempt a local run/debug of a Lambda function (all runtimes affected)

Expected behavior
Function runs with a user-defined region tied to the SAM environment (so the AWS_REGION variable will work)

Desktop (please complete the following information):

  • OS: All
  • Visual Studio Code Version: All
  • AWS Toolkit for Visual Studio Code Version: All

Additional context
We have a few implementation options:

  • Set the AWS_REGION env var with a valid region code
  • Pass the --region flag to the SAM CLI invoke call with a valid region code.
  • Pass the --profile flag to the SAM CLI invoke call with the selected AWS profile name. This requires that an ~/.aws/config is created at some point (we don't do this) that has a [profile <profileName>] entry containing a region value

JetBrains sets the AWS_REGION but uses the selected AWS region for the workspace (since they don't have a concept of multiple regions in the explorer).

Aside from pulling the value from ~/.aws/config, we can:

  • Pull the first region from the AWS explorer
  • Add region value to our template.json file
  • Prompt the user on run/debug for a region
    • We can cache this value for later
  • Use a hardcoded value (this breaks users who are testing the AWS_REGION variable)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions