Skip to content

Adding --region parameter as the region this Lambda function resides in #175

Closed

Description

@zhangzhx

The current way for providing the region of the Lambda function is using bash env var like
AWS_REGION=us-west-1 sam local invoke ....

This is implicit and not a regular bash command. Can you add a parameter --region us-west-1 to explicitly override the region environment variable?

Activity

  1. purefan commented on Oct 23, 2017

    @purefan
    Contributor

    This is the repository for AWS SAM Local, when you invoke a function you are executing code that resides in your computer, not in an aws environment, that is to say: there are no regions.

    Can you please describe what you're trying to do?

  2. bradleyjames commented on Oct 23, 2017

    @bradleyjames

    There are regions when interacting with other AWS resources from a lambda. I've ran into this issue as well.

  3. zhangzhx commented on Oct 23, 2017

    @zhangzhx
    ContributorAuthor

    @purefan I want to mock the Lambda environment in a specific region as much as possible with SAM Local. In the AWS Lambda runtime environment, you don't have to specify the region in the Credentials Provider chain, so that you can access AWS resources in the same region to the Lambda function. I want SAM Local to have a specific region configured as the environment variable same to the standard AWS Lambda.

  4. purefan commented on Oct 24, 2017

    @purefan
    Contributor

    Although I still fail to see the need for defining the region you can also use the env vars file if you prefer: sam local start-api --env-vars path_to.json

    The way I imaging going about it is by defining the region from a configuration file, and when using the sdk I would specify the region based on the value in the config file, for example AWS.config.update({region: my_config_object.region}); docs

  5. bradleyjames commented on Oct 24, 2017

    @bradleyjames

    The reason I'm fine with --region is it replicates the AWS CLI method of configuring the region. I think --env-vars works but it's the least favorable. The core concern that I believe @zhangzhx has, and I do as well, is sam local doesn't replicate the runtime environment. Each developer has to trip over it and determine how best to handle it on their own.

    My preference would be for sam local to:

    • read the region of the profile from ~/.aws/credentials if AWS_PROFILE is specified
    • read from a sam local specific default region (something like .samlocalrc) local to my project
    • use --region if specified
    • default 'us-east-1'

    The way I imaging going about it is by defining the region from a configuration file, and when using the sdk I would specify the region based on the value in the config file, for example AWS.config.update({region: my_config_object.region});

    Defining the region in a config file doesn't address determining the current region by inspecting AWS_REGION which is how most write their lambdas today.

  6. PaulMaddox commented on Oct 27, 2017

    @PaulMaddox
    Contributor

    +1. I agree that --region is the AWS standard way of doing this, and while the region can be specified in other ways, most people will try --region first.

    Marking this as a feature request that we should implement.

  7. SanderKnape commented on Nov 23, 2017

    @SanderKnape

    A +1 from me as well. I also tried to use --region first before I added the region to the Lambda function code.

  8. added
    type/feature
    and removed on Jan 7, 2018
  9. travis-edgar commented on Jan 11, 2018

    @travis-edgar

    +1. I first tried using AWS_DEFAULT_REGION as a bash env var. I found this post and @zhangzhx comment which solved my issue.

    --region for the win.

    Also where in the docs is it mentioned that one should use AWS_REGION specifically?

  10. dementiev commented on Feb 23, 2018

    @dementiev

    +1 for region parameter, i receive 'region 'us-east-1' is wrong; expecting 'eu-central-1' '

  11. domZippilli commented on Apr 12, 2018

    @domZippilli

    +1

  12. red8888 commented on Apr 23, 2018

    @red8888

    +1

  13. sanathkr commented on May 8, 2018

    @sanathkr

    Can you try the latest release - https://github.com/awslabs/aws-sam-cli/releases/tag/v0.3.0? I believe this is fixed. Feel free to re-open Issue if not. You can use AWS_REGION or AWS_DEFAULT_REGION and it will work.

    --region is not supported yet though. So I will keep this Issue open for tracking that

  14. added
    contributors/good-first-issue
    contributors/welcome
    on May 31, 2018
  15. red8888 commented on Jun 18, 2018

    @red8888

    Another use case i have is a lambda im deploying to multiple regions. So I can reset the env var before I call sam deploy but thats not great.

    Should just not use sam at all and just use:
    aws cloudformation package
    aws cloudformation deploy

    Those commands have a region switch, and they are the same as the sam ones right?

  16. hb-adw commented on Jun 21, 2018

    @hb-adw

    Another way to change region is to add a variable "region" in your file ".aws/credentials" with your profile. Then you could add --profile <profile_name> as parameter

  17. added
    stage/waiting-for-release
    on Aug 10, 2018
  18. jfuss commented on Aug 29, 2018

    @jfuss
    Contributor

    Closing this as it was released in 0.6.0

  19. removed
    stage/waiting-for-release
    on Aug 29, 2018
  20. ndelvalle commented on Sep 4, 2018

    @ndelvalle

    Is this documented somewhere so I can take a look? I could not find it 😕Also, can this be used to deploy lambdas to specific regions as well, not just invoke them?

  21. jfuss commented on Sep 4, 2018

    @jfuss
    Contributor

    @ndelvalle Documented as in? If you run the --help on the sam local [start-lambda|invoke|start-api], you will see --region as an option.

    sam deploy should already have this option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributors/good-first-issuecontributors/welcometype/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions