AWS CFN Lambda 未将所有消息发送到 SQS

问题描述

我是 AWS cloudformation 的新手,我的堆栈有问题。我有这些工作,但出了点问题。

假设我有一个 ArtifactBucket 堆栈,其中包含我的 .Net 核心 lambda 和 IAM 用户、角色和 KMS 密钥的 zip 文件

我有这个主堆栈,它有一个 Creator lambda 将向 SQS Queue 发送消息。处理器功能将接收该消息并将其发送到 SNS,然后 SNS 向我发送电子邮件(请参阅订阅

这一切都在 AWS 控制台中部署得很好,但我发现当我调用 lambda 时,我需要在收到消息之前多次调用它,并且一些消息丢失了。例如..我会一个一个发送5条消息,只收到4条消息。

我怀疑它是 lambda 和队列的超时问题,但我正在努力查明它。

您是否发现我在此主模板中遗漏了任何明显的东西,或者队列属性 va lambda 时间值是否存在问题?

   "DelaySeconds" : 0,"MessageRetentionPeriod" : 900,"ReceiveMessageWaitTimeSeconds" : 5,"VisibilityTimeout" : 120,

堆栈模板:

{
  "AWstemplateFormatVersion": "2010-09-09","Description": "Template to create IntergrationQueue,Intergrator and use storage bucket","Parameters": {
    "ArtifactBucketName": {
      "Type": "String"
    },"StorageBucketArn": {
      "Type": "String"
    },"JogDayIAMUserArn": {
      "Type": "String"
    },"JogDayIAMRoleArn": {
      "Type": "String"
    },"JogDayKMSKeyArn": {
      "Type": "String"
    }
  },"Resources": {  
    "DLQ": {
      "Type": "AWS::SQS::Queue","DeletionPolicy": "Delete","Properties": {
        "KmsMasterKeyId": {
          "Ref": "JogDayKMSKeyArn"
        }
      }
    },"Queue": {
      "Type": "AWS::SQS::Queue","DependsOn": "DLQ","Properties": {
        "QueueName": "JogDayQueue","DelaySeconds" : 0,"RedrivePolicy": {        
          "deadLetterTargetArn": {
            "Fn::GetAtt": [
              "DLQ","Arn"
            ]
          },"maxReceiveCount" : 10          
        },"KmsMasterKeyId": {
          "Ref": "JogDayKMSKeyArn"
        },"Tags": [
          {
            "Key": "jogday","Value": "jogday"
          }
        ]
      }
    },"JogDayTopic": {
      "Type": "AWS::SNS::Topic","Properties": {
        "displayName": "JogDay topic","KmsMasterKeyId" : {"Ref":"JogDayKMSKeyArn"},"TopicName" : "JogDayEmailTopic","JogDayQueuePolicy": {
      "Type": "AWS::SQS::QueuePolicy","Description" : "Intergration Queue Policy","DependsOn" : ["Queue","CreatorLambdaFunction"],"DeletionPolicy" : "Delete","Properties": {      
        "Queues": [{ "Ref":"Queue" }],"PolicyDocument": {
          "Statement": [
            {
              "Effect": "Allow","Principal": {
                "Service": "sns.amazonaws.com"
              },"Action": [
                "SQS:SendMessage","SQS:ReceiveMessage"
              ],"Resource": {
                "Fn::GetAtt": [
                  "Queue","Arn"
                ]
              },"Condition": {
                "ArnEquals": {
                  "aws:SourceArn":{
                    "Fn::GetAtt": [
                      "CreatorLambdaFunction","Arn"
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    },"JogDaySubscription": {
      "Type": "AWS::SNS::Subscription","Properties": {      
        "TopicArn": {
          "Ref": "JogDayTopic"
        },"Endpoint": "some.email@gmail.com","Protocol": "email"
      },"DependsOn": [
        "JogDayTopic"
      ]
    },"CreatorLambdaFunction": {
      "Type": "AWS::Lambda::Function","Properties": {
        "Runtime": "dotnetcore3.1","FunctionName": "CreatorFunction","Description": "Function that will take a message and send it to a SQS queue","Code": {
          "S3Bucket": {
            "Ref": "ArtifactBucketName"
          },"S3Key": "CreatorFunction.zip"
        },"Handler": "CreatorFunction::CreatorFunction.Function::FunctionHandler","Role": { "Ref": "JogDayIAMRoleArn" },"DeadLetterConfig": {
          "TargetArn": {
            "Fn::GetAtt": [
              "DLQ","Arn"
            ]
          }
        },"Value": "jogday"
          }
        ],"Timeout": 120,"KmsKeyArn": {
          "Ref": "JogDayKMSKeyArn"
        },"Environment": {
          "Variables": {
            "QueueName": {
              "Fn::GetAtt": [
                "Queue","QueueName"
              ]
            },"DLQName": {
              "Fn::GetAtt": [
                "DLQ","QueueName"
              ]
            }
          }
        }
      }
    },"CreatorLambdaFunctionInvokePermission": {
      "Type": "AWS::Lambda::Permission","Properties": {
        "FunctionName": {
          "Fn::GetAtt": [
            "CreatorLambdaFunction","Arn"
          ]
        },"Action": "lambda:InvokeFunction","Principal": {
          "Ref": "JogDayIAMUserArn"
        },"SourceAccount": {
          "Ref": "AWS::AccountId"
        }
      }
    },"ProcessorLambdaFunction": {
      "Type": "AWS::Lambda::Function","DLQ","JogDayTopic"],"FunctionName": "ProcessorFunction","Description": "Function that will receive a message from sqs and send it to sns","S3Key": "ProcessorFunction.zip"
        },"Handler": "ProcessorFunction::ProcessorFunction.Function::FunctionHandler","JogDayTopicArn": {"Ref" : "JogDayTopic" },"JogDayTopicName": {
              "Fn::GetAtt": [
                "JogDayTopic","TopicName"
              ]
            }       
          }
        }
      }
    },"ProcessorLambdaFunctionInvokePermission": {
      "Type": "AWS::Lambda::Permission","Properties": {
        "FunctionName": {
          "Fn::GetAtt": [
            "ProcessorLambdaFunction","ProcessorLambdaEventSourceMapping": {
      "Type": "AWS::Lambda::EventSourceMapping","DependsOn": ["ProcessorLambdaFunction","Queue"],"Properties": {
       "BatchSize" : 10,"Enabled" : true,"EventSourceArn" : {
          "Fn::GetAtt": [
            "Queue","FunctionName" : {
          "Fn::GetAtt": [
            "ProcessorLambdaFunction","Arn"
          ]
        }     
      }
    }
  },"Outputs": {
    "QueueArn": {
      "Value": {
        "Fn::GetAtt": [
          "Queue","Arn"
        ]
      }
    },"DLQArn": {
      "Value": {
        "Fn::GetAtt": [
          "DLQ","JogDayTopicName":{
     "Value": {
        "Fn::GetAtt": [
          "JogDayTopic","TopicName"
        ]
      }
    }
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)