【问题标题】:How can i set the maximumRetryAttempt for aws lambda in the cloudformation lambda?如何在 cloudformation lambda 中为 aws lambda 设置 maximumRetryAttempt?
【发布时间】:2020-07-15 19:49:51
【问题描述】:

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

  "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
       }
    }
 }
}

【问题讨论】:

  • 该 lambda 函数是作为此 cloudformation 模板的一部分创建的吗?
  • @franklinsijo 是的,lambda 函数是在 cloudformation 模板中创建的
  • 请用完整的模板更新帖子!

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

您的问题可能已经解决,但您可以改进代码。当您使用无服务器 (SAM) 时,您可以直接在 lambda 资源属性中指定 EventInvokeConfig,而无需创建其他资源。请找到下面的sn-p:

{
    "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 对象中指定其他属性,例如DestinationConfigMaximumEventAgeInSeconds

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

【讨论】:

    【解决方案2】:

    您可以使用Ref 内在函数。对于AWS::Serverless::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"
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 2018-11-13
      • 1970-01-01
      • 2020-11-05
      • 2018-10-27
      • 2017-10-14
      • 1970-01-01
      相关资源
      最近更新 更多