小编got*_*012的帖子

aws-sam-local环境变量

我在这里阅读自述文件:https://github.com/awslabs/aws-sam-local

我已经写在python 3.6拉姆达及其类似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
Run Code Online (Sandbox Code Playgroud)

我在lambda中有环境变量但在启动时无法连接它们.文档说我可以创建一个environments.json文件并在invoke命令上附加以下内容:使用--env-vars invoke参数

我的环境文件看起来像示例,我收到一个错误: Unable to find environment variable: api_key

environment.json看起来像这样:

{
  "MyFunction1": {
    "api_key": "123456789",
    "BUCKET_NAME": "testBucket"
  }
}
Run Code Online (Sandbox Code Playgroud)

命令我运行是这样的:

sam local invoke MyFunction1 --env-vars environment_variables.json -e event.json
Run Code Online (Sandbox Code Playgroud)

有人能提供额外的见解吗?

aws-lambda aws-sam-cli serverless

18
推荐指数
4
解决办法
1万
查看次数

标签 统计

aws-lambda ×1

aws-sam-cli ×1

serverless ×1