![](/img/trans.png)
[英]How Can I Load The Output of AWS Cloudformation In AWS Lambda?
[英]How can i set the maximumRetryAttempt for aws lambda in the cloudformation lambda?
我有一个通过 Visual Studio 创建的无服务器项目,我正在寻找在 cloudformation 模板中设置特定 lambda 的最大重试次数。 我看到了 EventInvokeConfig,但是 lambda function 名称是自动生成的,并且每个环境都不同。 我想知道是否有特定于 aws 的参数来获取 lambda function 名称?
"EventInvokeConfig": {
"Type" : "AWS::Lambda::EventInvokeConfig",
"Properties" : {
"FunctionName" : "???",
"MaximumRetryAttempts" : 0,
"Qualifier" : "$LATEST"
}
}
这是我的无服务器模板
{
"AWSTemplateFormatVersion":"2010-09-09",
"Transform":"AWS::Serverless-2016-10-31",
"Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Resources":{
"MyFunctionLambda":{
"Type":"AWS::Serverless::Function",
"Properties":{
"Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
"Runtime":"dotnetcore2.1",
"CodeUri":"",
"Description":"Default function",
"MemorySize":512,
"Timeout":60,
"Role":null
}
}
}
}
您可以使用Ref
内在 function。 对于AWS::Serverless::Function
类型的资源,返回值为 function 的名称。
这可以在模板中定义的其他资源中引用。 对于EventInvokeConfig
,模板看起来像
{
"AWSTemplateFormatVersion":"2010-09-09",
"Transform":"AWS::Serverless-2016-10-31",
"Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Resources":{
"MyFunctionLambda":{
"Type":"AWS::Serverless::Function",
"Properties":{
"Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
"Runtime":"dotnetcore2.1",
"CodeUri":"",
"Description":"Default function",
"MemorySize":512,
"Timeout":60,
"Role":null
}
},
"EventInvokeConfig": {
"Type" : "AWS::Lambda::EventInvokeConfig",
"Properties" : {
"FunctionName" : { "Ref" : MyFunctionLambda },
"MaximumRetryAttempts" : 0,
"Qualifier" : "$LATEST"
}
}
}
}
您的问题可能已经解决,但您可以改进代码。 当您使用无服务器 (SAM) 时,您可以直接在 lambda 资源属性中指定EventInvokeConfig
,而无需创建其他资源。 请找到以下代码段:
{
"AWSTemplateFormatVersion":"2010-09-09",
"Transform":"AWS::Serverless-2016-10-31",
"Description":"An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Resources":{
"MyFunctionLambda":{
"Type":"AWS::Serverless::Function",
"Properties":{
"Handler":"MyPlatformServerless::MyPlatformServerless.Lambdas.MyFunctionLambda::FunctionHandler",
"Runtime":"dotnetcore2.1",
"CodeUri":"",
"Description":"Default function",
"MemorySize":512,
"Timeout":60,
"Role":null,
"EventInvokeConfig": {
"MaximumRetryAttempts" : 0
}
}
}
}
}
您还可以在EventInvokeConfig
object 中指定其他属性,例如DestinationConfig
和MaximumEventAgeInSeconds
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.