gpt4 book ai didi

amazon-web-services - CloudFormation - 从 Lambda 代码访问参数

转载 作者:行者123 更新时间:2023-12-01 12:26:42 24 4
gpt4 key购买 nike

我有一个 CloudFormation 模板,如下所示:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template will deploy stuff",
"Parameters":{
"myParamToLambdaFunction" : {
"Description" : "Please enter the the value",
"Type" : "String",
"ConstraintDescription" : "must have some value."
}
},
"Resources": {
"SecGrpValidatorFromCFTemplate": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": "mylambdafunctionname",
"Handler": "myfile.lambda_handler",
"Role": {
"Fn::GetAtt": ["somerole", "Arn"]
},
"Timeout": "30",
"Runtime": "python2.7",
"Code": {
"S3Bucket":"mybucket",
"S3Key":"mylambdafunction.zip"
}
}
}
}

我需要将 myParamToLambdaFunction 的值传递给 Lambda 函数。

有办法吗?

最佳答案

截至18 Nov 2016 ,AWS Lambda 现在支持 environment variables ,CloudFormation 通过 Environment 支持属性 AWS::Lambda::Function资源。

向您的资源添加一个 Environment 属性,如下所示:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "This template will deploy stuff",
"Parameters":{
"myParamToLambdaFunction" : {
"Description" : "Please enter the the value",
"Type" : "String",
"ConstraintDescription" : "must have some value."
}
},
"Resources": {
"SecGrpValidatorFromCFTemplate": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": "mylambdafunctionname",
"Handler": "myfile.lambda_handler",
"Role": {
"Fn::GetAtt": ["somerole", "Arn"]
},
"Timeout": "30",
"Runtime": "python2.7",
"Code": {
"S3Bucket":"mybucket",
"S3Key":"mylambdafunction.zip"
},
"Environment": {
"Variables": {
"myParam": {
"Ref": "myParamToLambdaFunction"
}
}
}
}
}
}

然后根据您的运行时平台引用已部署的 Lambda 函数中的环境变量(例如,Python 中的 os.environ['myParam'])。

关于amazon-web-services - CloudFormation - 从 Lambda 代码访问参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38707808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com