RMi*_*ish 2 amazon-s3 amazon-web-services aws-cloudformation aws-lambda
我的 Lambda 代码存储在 S3 存储桶中。我使用 CloudFormation 在子帐户中进行部署。
Lambda 代码片段:
def lambda_handler(event,context):
ids = ["${id}"]
Run Code Online (Sandbox Code Playgroud)
CloudFormation 使用参数将以下内容id作为:
Parameters:
id:
Type: String
Description: Name of id.
Default: abc
Run Code Online (Sandbox Code Playgroud)
但是,id不会在 lambda 中填充,因为代码存储在 S3 存储桶中。
怎么办?
Joh*_*ein 11
从你的描述来看,你的要求是:
您可以通过环境变量将参数传递给 Lambda 函数来实现这一点。
在 CloudFormation 模板中定义 Lambda 函数时,可以提供环境变量:
Type: AWS::Lambda::Function
Properties:
Code:
Code
Environment:
Variables:
id:
Ref: PARAMETER-NAME
...
Run Code Online (Sandbox Code Playgroud)
在这种情况下,变量的值来自参数。
在您的 Lambda 代码中,您将访问环境变量。这是一个 Python 示例:
Type: AWS::Lambda::Function
Properties:
Code:
Code
Environment:
Variables:
id:
Ref: PARAMETER-NAME
...
Run Code Online (Sandbox Code Playgroud)
参考:
| 归档时间: |
|
| 查看次数: |
4399 次 |
| 最近记录: |