You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding --region parameter as the region this Lambda function resides in #175
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?
Reacted by Brad Reynolds, Sander Knape, Fred Myerscough, ryanwkan, Michael, Shuji Honda, Kien Pham, Andrea Di Giorgi, red8888, nigelgardiner and 2 more
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.
@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.
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
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.
Reacted by goldenbearkin, Fred Myerscough, Steve Slotnick, Michael, Mark, Matt Healy, Seinna Gausman and Moemen Elzeiny
+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.
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
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?
Activity
purefan commentedon Oct 23, 2017
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?
bradleyjames commentedon Oct 23, 2017
There are regions when interacting with other AWS resources from a lambda. I've ran into this issue as well.
zhangzhx commentedon Oct 23, 2017
@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.
purefan commentedon Oct 24, 2017
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.jsonThe 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});docsbradleyjames commentedon Oct 24, 2017
The reason I'm fine with
--regionis it replicates the AWS CLI method of configuring the region. I think--env-varsworks 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:
AWS_PROFILEis specifiedDefining the region in a config file doesn't address determining the current region by inspecting
AWS_REGIONwhich is how most write their lambdas today.PaulMaddox commentedon Oct 27, 2017
+1. I agree that
--regionis the AWS standard way of doing this, and while the region can be specified in other ways, most people will try--regionfirst.Marking this as a feature request that we should implement.
SanderKnape commentedon Nov 23, 2017
A +1 from me as well. I also tried to use --region first before I added the region to the Lambda function code.
travis-edgar commentedon Jan 11, 2018
+1. I first tried using
AWS_DEFAULT_REGIONas a bash env var. I found this post and @zhangzhx comment which solved my issue.--regionfor the win.Also where in the docs is it mentioned that one should use
AWS_REGIONspecifically?dementiev commentedon Feb 23, 2018
+1 for region parameter, i receive 'region 'us-east-1' is wrong; expecting 'eu-central-1' '
domZippilli commentedon Apr 12, 2018
+1
red8888 commentedon Apr 23, 2018
+1
sanathkr commentedon May 8, 2018
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.
--regionis not supported yet though. So I will keep this Issue open for tracking thatred8888 commentedon Jun 18, 2018
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?
hb-adw commentedon Jun 21, 2018
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
jfuss commentedon Aug 29, 2018
Closing this as it was released in 0.6.0
ndelvalle commentedon Sep 4, 2018
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?
jfuss commentedon Sep 4, 2018
@ndelvalle Documented as in? If you run the
--helpon the sam local [start-lambda|invoke|start-api], you will see--regionas an option.sam deployshould already have this option.