3 個答案
- 最新
- 最多得票
- 最多評論
1
It's not well documented but any env vars that you want to override via --env-vars
must be defined in the SAM template. I too had this problem until I finally ran across https://stackoverflow.com/questions/48104665/aws-sam-local-environment-variables/48139216#48139216.
已回答 5 個月前
0
If you want to use the generated table name in the stack you can use a cloudformation construct called !Ref
and set an environment variable for the lambda function that can be used. As indicated here, dynamo outputs the name of the table that you can then reference in your lambda function as an env variable. Here is an example.
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
....
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
DYNAMODB_TABLE_NAME: !Ref DynamoDBTable
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
已回答 2 年前
0
Try putting the function name at the end of the invoke line:
sam local invoke -e events/event-post-item.json --profile myprofile -n local.json putItemFunction
相關內容
- AWS 官方已更新 3 年前
- AWS 官方已更新 1 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 3 年前
That's already done. The problem is, if I skip
--env-vars env.json
part from thesam local invoke
command thenprocess.env.DYNAMODB_TABLE_NAME
value I get is justDynamoDBTable
. Not the correct name of database that was generated with the stack, ex:DynamoDBTable-T69PQM8X9UBJ
...I guess I understand what's going on. I can't get the generated DB name to be sent to the
process.env
automatically when invoking locally. I have to get the generated names from the deploy output and pipe it to some script to be injected it intoenv.json
for my local invokes to be automatic.