我在这里遵循README:https://github.com/awslabs/aws-sam-local
我有一个用Python 3.6编写的Lambda函数,与这里的helloworld示例类似:https://github.com/awslabs/aws-sam-local/tree/develop/samples/hello-world/python
template.yml如下所示:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: MyFunction1 API
Resources:
MyFunction1:
Type: AWS::Serverless::Function
Properties:
FunctionName: MyFunction1
Handler: lambda_module.lambda_handler
Runtime: python3.6
CodeUri: lambda.zip
MemorySize: 128
Timeout: 10
Policies:
-AWSLamdbaBasicExecutionRole
Events:
BingLambdaEndpoint:
Type: Api
Properties:
Path: MyFunction1/search
Method: get
我在lambda函数中有环境变量,但是无法在启动时连接它们。文档说我可以创建一个environments.json文件,并在调用命令上附加以下内容:使用invoke的 --env-vars参数
我的环境文件看起来像这个例子,但是我得到了一个错误:Unable to find environment variable: api_key
environment.json如下:
{
"MyFunction1": {
"api_key": "123456789",
"BUCKET_NAME": "testBucket"
}
}
我运行的命令如下:
sam local invoke MyFunction1 --env-vars environment_variables.json -e event.json
有人能提供额外的见解吗?
Globals: Function: Environment: Variables: api_key:
- James Burke