title: AWS CFN Lambda not sending all messages to SQS
body: <p>I am new to AWS cloudformation and have an issue with my stacks.  I had these working but somewhere something went wrong.</p>
  <p>Asume I have a ArtifactBucket stack with the zip files for my .Net core lambdas and the IAM user, role and KMS key.</p>
  <p>I have this main stack which has a <code>Creator lambda</code> that will send a message to the <code>SQS Queue</code>. The processor function will receive that message and send it to SNS which then send me an email (see subscription)</p>
  <p>It all deploys fine in AWS console but Im finding that when I invoke the lambda, I need to invoke it multiple times before I receive a message and some of the messages are lost. For example.. Ill send 5 messages one after another and only get message 4.</p>
  <p>I suspect its a timeout issue on the lambda, and the Queue but I i'm struggling to pinpoint it down.</p>
  <p>Do you spot anythign obvious I am either missing in this main template, or is there an issue with the Queue properties va the lambda time values?</p>
  <pre><code>   &quot;DelaySeconds&quot; : 0,
     &quot;MessageRetentionPeriod&quot; : 900,
     &quot;ReceiveMessageWaitTimeSeconds&quot; : 5,
     &quot;VisibilityTimeout&quot; : 120,
  </code></pre>
  <p>stack-template:</p>
  <pre><code>{
    &quot;AWSTemplateFormatVersion&quot;: &quot;2010-09-09&quot;,
    &quot;Description&quot;: &quot;Template to create IntergrationQueue, Intergrator and use storage bucket&quot;,
    &quot;Parameters&quot;: {
      &quot;ArtifactBucketName&quot;: {
        &quot;Type&quot;: &quot;String&quot;
      },
      &quot;StorageBucketArn&quot;: {
        &quot;Type&quot;: &quot;String&quot;
      },
      &quot;JogDayIAMUserArn&quot;: {
        &quot;Type&quot;: &quot;String&quot;
      },
      &quot;JogDayIAMRoleArn&quot;: {
        &quot;Type&quot;: &quot;String&quot;
      },
      &quot;JogDayKMSKeyArn&quot;: {
        &quot;Type&quot;: &quot;String&quot;
      }
    },
    &quot;Resources&quot;: {  
      &quot;DLQ&quot;: {
        &quot;Type&quot;: &quot;AWS::SQS::Queue&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;Properties&quot;: {
          &quot;KmsMasterKeyId&quot;: {
            &quot;Ref&quot;: &quot;JogDayKMSKeyArn&quot;
          }
        }
      },
      &quot;Queue&quot;: {
        &quot;Type&quot;: &quot;AWS::SQS::Queue&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;DependsOn&quot;: &quot;DLQ&quot;,
        &quot;Properties&quot;: {
          &quot;QueueName&quot;: &quot;JogDayQueue&quot;,
          &quot;DelaySeconds&quot; : 0,
          &quot;MessageRetentionPeriod&quot; : 900,
          &quot;ReceiveMessageWaitTimeSeconds&quot; : 5,
          &quot;VisibilityTimeout&quot; : 120,
          &quot;RedrivePolicy&quot;: {        
            &quot;deadLetterTargetArn&quot;: {
              &quot;Fn::GetAtt&quot;: [
                &quot;DLQ&quot;,
                &quot;Arn&quot;
              ]
            },
            &quot;maxReceiveCount&quot; : 10          
          },
          &quot;KmsMasterKeyId&quot;: {
            &quot;Ref&quot;: &quot;JogDayKMSKeyArn&quot;
          },
          &quot;Tags&quot;: [
            {
              &quot;Key&quot;: &quot;jogday&quot;,
              &quot;Value&quot;: &quot;jogday&quot;
            }
          ]
        }
      },
      &quot;JogDayTopic&quot;: {
        &quot;Type&quot;: &quot;AWS::SNS::Topic&quot;,      
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;Properties&quot;: {
          &quot;DisplayName&quot;: &quot;JogDay topic&quot;,
          &quot;KmsMasterKeyId&quot; : {&quot;Ref&quot;:&quot;JogDayKMSKeyArn&quot;},        
          &quot;TopicName&quot; : &quot;JogDayEmailTopic&quot;,      
          &quot;Tags&quot;: [
            {
              &quot;Key&quot;: &quot;jogday&quot;,
              &quot;Value&quot;: &quot;jogday&quot;
            }
          ]
        }
      },
      &quot;JogDayQueuePolicy&quot;: {
        &quot;Type&quot;: &quot;AWS::SQS::QueuePolicy&quot;,
        &quot;Description&quot; : &quot;Intergration Queue Policy&quot;,
        &quot;DependsOn&quot; : [&quot;Queue&quot;,&quot;CreatorLambdaFunction&quot;],
        &quot;DeletionPolicy&quot; : &quot;Delete&quot;,      
        &quot;Properties&quot;: {      
          &quot;Queues&quot;: [{ &quot;Ref&quot;:&quot;Queue&quot; }],        
          &quot;PolicyDocument&quot;: {
            &quot;Statement&quot;: [
              {
                &quot;Effect&quot;: &quot;Allow&quot;,
                &quot;Principal&quot;: {
                  &quot;Service&quot;: &quot;sns.amazonaws.com&quot;
                },
                &quot;Action&quot;: [
                  &quot;SQS:SendMessage&quot;,
                  &quot;SQS:ReceiveMessage&quot;
                ],
                &quot;Resource&quot;: {
                  &quot;Fn::GetAtt&quot;: [
                    &quot;Queue&quot;,
                    &quot;Arn&quot;
                  ]
                },
                &quot;Condition&quot;: {
                  &quot;ArnEquals&quot;: {
                    &quot;aws:SourceArn&quot;:{
                      &quot;Fn::GetAtt&quot;: [
                        &quot;CreatorLambdaFunction&quot;,
                        &quot;Arn&quot;
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      },
      &quot;JogDaySubscription&quot;: {
        &quot;Type&quot;: &quot;AWS::SNS::Subscription&quot;,      
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;Properties&quot;: {      
          &quot;TopicArn&quot;: {
            &quot;Ref&quot;: &quot;JogDayTopic&quot;
          },
          &quot;Endpoint&quot;: &quot;some.email@gmail.com&quot;,
          &quot;Protocol&quot;: &quot;email&quot;
        },
        &quot;DependsOn&quot;: [
          &quot;JogDayTopic&quot;
        ]
      },
      &quot;CreatorLambdaFunction&quot;: {
        &quot;Type&quot;: &quot;AWS::Lambda::Function&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,    
        &quot;Properties&quot;: {
          &quot;Runtime&quot;: &quot;dotnetcore3.1&quot;,
          &quot;FunctionName&quot;: &quot;CreatorFunction&quot;,
          &quot;Description&quot;: &quot;Function that will take a message and send it to a SQS queue&quot;,
          &quot;Code&quot;: {
            &quot;S3Bucket&quot;: {
              &quot;Ref&quot;: &quot;ArtifactBucketName&quot;
            },
            &quot;S3Key&quot;: &quot;CreatorFunction.zip&quot;
          },
          &quot;Handler&quot;: &quot;CreatorFunction::CreatorFunction.Function::FunctionHandler&quot;,
          &quot;Role&quot;: { &quot;Ref&quot;: &quot;JogDayIAMRoleArn&quot; },
          &quot;DeadLetterConfig&quot;: {
            &quot;TargetArn&quot;: {
              &quot;Fn::GetAtt&quot;: [
                &quot;DLQ&quot;,
                &quot;Arn&quot;
              ]
            }
          },        
          &quot;Tags&quot;: [
            {
              &quot;Key&quot;: &quot;jogday&quot;,
              &quot;Value&quot;: &quot;jogday&quot;
            }
          ],
          &quot;Timeout&quot;: 120,        
          &quot;KmsKeyArn&quot;: {
            &quot;Ref&quot;: &quot;JogDayKMSKeyArn&quot;
          },
          &quot;Environment&quot;: {
            &quot;Variables&quot;: {
              &quot;QueueName&quot;: {
                &quot;Fn::GetAtt&quot;: [
                  &quot;Queue&quot;,
                  &quot;QueueName&quot;
                ]
              },
              &quot;DLQName&quot;: {
                &quot;Fn::GetAtt&quot;: [
                  &quot;DLQ&quot;,
                  &quot;QueueName&quot;
                ]
              }
            }
          }
        }
      },
      &quot;CreatorLambdaFunctionInvokePermission&quot;: {
        &quot;Type&quot;: &quot;AWS::Lambda::Permission&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;Properties&quot;: {
          &quot;FunctionName&quot;: {
            &quot;Fn::GetAtt&quot;: [
              &quot;CreatorLambdaFunction&quot;,
              &quot;Arn&quot;
            ]
          },
          &quot;Action&quot;: &quot;lambda:InvokeFunction&quot;,
          &quot;Principal&quot;: {
            &quot;Ref&quot;: &quot;JogDayIAMUserArn&quot;
          },
          &quot;SourceAccount&quot;: {
            &quot;Ref&quot;: &quot;AWS::AccountId&quot;
          }
        }
      },
      &quot;ProcessorLambdaFunction&quot;: {
        &quot;Type&quot;: &quot;AWS::Lambda::Function&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,    
        &quot;DependsOn&quot; : [&quot;Queue&quot;,&quot;DLQ&quot;,&quot;JogDayTopic&quot;],
        &quot;Properties&quot;: {
          &quot;Runtime&quot;: &quot;dotnetcore3.1&quot;,
          &quot;FunctionName&quot;: &quot;ProcessorFunction&quot;,
          &quot;Description&quot;: &quot;Function that will receive a message from sqs and send it to sns&quot;,
          &quot;Code&quot;: {
            &quot;S3Bucket&quot;: {
              &quot;Ref&quot;: &quot;ArtifactBucketName&quot;
            },
            &quot;S3Key&quot;: &quot;ProcessorFunction.zip&quot;
          },
          &quot;Handler&quot;: &quot;ProcessorFunction::ProcessorFunction.Function::FunctionHandler&quot;,        
          &quot;Role&quot;: { &quot;Ref&quot;: &quot;JogDayIAMRoleArn&quot; },
          &quot;DeadLetterConfig&quot;: {
            &quot;TargetArn&quot;: {
              &quot;Fn::GetAtt&quot;: [
                &quot;DLQ&quot;,
                &quot;Arn&quot;
              ]
            }
          },        
          &quot;Tags&quot;: [
            {
              &quot;Key&quot;: &quot;jogday&quot;,
              &quot;Value&quot;: &quot;jogday&quot;
            }
          ],
          &quot;Timeout&quot;: 120,
          &quot;KmsKeyArn&quot;: {
            &quot;Ref&quot;: &quot;JogDayKMSKeyArn&quot;
          },
          &quot;Environment&quot;: {
            &quot;Variables&quot;: {
              &quot;QueueName&quot;: {
                &quot;Fn::GetAtt&quot;: [
                  &quot;Queue&quot;,
                  &quot;QueueName&quot;
                ]
              },
              &quot;DLQName&quot;: {
                &quot;Fn::GetAtt&quot;: [
                  &quot;DLQ&quot;,
                  &quot;QueueName&quot;
                ]
              },
              &quot;JogDayTopicArn&quot;: {&quot;Ref&quot; : &quot;JogDayTopic&quot; },         
              &quot;JogDayTopicName&quot;: {
                &quot;Fn::GetAtt&quot;: [
                  &quot;JogDayTopic&quot;,
                  &quot;TopicName&quot;
                ]
              }       
            }
          }
        }
      },
      &quot;ProcessorLambdaFunctionInvokePermission&quot;: {
        &quot;Type&quot;: &quot;AWS::Lambda::Permission&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;Properties&quot;: {
          &quot;FunctionName&quot;: {
            &quot;Fn::GetAtt&quot;: [
              &quot;ProcessorLambdaFunction&quot;,
              &quot;Arn&quot;
            ]
          },
          &quot;Action&quot;: &quot;lambda:InvokeFunction&quot;,
          &quot;Principal&quot;: {
            &quot;Ref&quot;: &quot;JogDayIAMUserArn&quot;
          },
          &quot;SourceAccount&quot;: {
            &quot;Ref&quot;: &quot;AWS::AccountId&quot;
          }
        }
      },
      &quot;ProcessorLambdaEventSourceMapping&quot;: {
        &quot;Type&quot;: &quot;AWS::Lambda::EventSourceMapping&quot;,
        &quot;DeletionPolicy&quot;: &quot;Delete&quot;,
        &quot;DependsOn&quot;: [&quot;ProcessorLambdaFunction&quot;,&quot;Queue&quot;],
        &quot;Properties&quot;: {
         &quot;BatchSize&quot; : 10,
         &quot;Enabled&quot; : true,
         &quot;EventSourceArn&quot; : {
            &quot;Fn::GetAtt&quot;: [
              &quot;Queue&quot;,
              &quot;Arn&quot;
            ]
          },
          &quot;FunctionName&quot; : {
            &quot;Fn::GetAtt&quot;: [
              &quot;ProcessorLambdaFunction&quot;,
              &quot;Arn&quot;
            ]
          }     
        }
      }
    },
    &quot;Outputs&quot;: {
      &quot;QueueArn&quot;: {
        &quot;Value&quot;: {
          &quot;Fn::GetAtt&quot;: [
            &quot;Queue&quot;,
            &quot;Arn&quot;
          ]
        }
      },
      &quot;DLQArn&quot;: {
        &quot;Value&quot;: {
          &quot;Fn::GetAtt&quot;: [
            &quot;DLQ&quot;,
            &quot;Arn&quot;
          ]
        }
      },
      &quot;JogDayTopicName&quot;:{
       &quot;Value&quot;: {
          &quot;Fn::GetAtt&quot;: [
            &quot;JogDayTopic&quot;,
            &quot;TopicName&quot;
          ]
        }
      }
    }
  }
  </code></pre>