首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在cloudformation中为aws设置maximumRetryAttempt?

问如何在cloudformation中为aws设置maximumRetryAttempt?
EN

Stack Overflow用户
提问于 2020-04-03 15:33:30
回答 2查看 3.1K关注 0票数 3

我有一个通过visual创建的无服务器项目,我正在寻找在cloudformation模板中设置特定lambda的maximumRetryAttempt。我看到了EventInvokeConfig,但是lambda函数名是自动生成的,并且与每个环境不同。我想知道是否有一个aws特定的参数来获得一个lambda函数名?

代码语言:javascript
复制
  "EventInvokeConfig": {
  "Type" : "AWS::Lambda::EventInvokeConfig",
  "Properties" : {
      "FunctionName" : "???",
      "MaximumRetryAttempts" : 0,
      "Qualifier" : "$LATEST"
    }
}

这是我的无服务器模板

代码语言:javascript
复制
{
 "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
       }
    }
 }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-06 02:36:52

您可以使用Ref固有函数。对于AWS::Serverless::Function类型的资源,返回的值是函数的名称。

这可以在模板中定义的其他资源中引用。对于EventInvokeConfig,模板看起来像

代码语言:javascript
复制
{
    "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"
            }
        }
    }
}
票数 3
EN

Stack Overflow用户

发布于 2021-07-17 05:40:30

您的问题可能已经解决,但您可以改进代码。在使用Serverless (SAM)时,可以在lambda资源属性中直接指定EventInvokeConfig,而不需要创建其他资源。请找到以下片段:

代码语言:javascript
复制
{
    "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
                }
            }
        }
    }
}

您还可以在DestinationConfig对象中指定其他属性,如MaximumEventAgeInSeconds和EventInvokeConfig。

参考资料:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-eventinvokeconfiguration.html

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61015330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档