Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to update maximum_batching_window_in_seconds in aws lambda event source mapping for SQS event source type #16518

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws/resource_aws_lambda_event_source_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta inte
return fmt.Errorf("Error updating event source mapping: %s", err)
}

if eventSourceArn.Service != "sqs" {
params.MaximumBatchingWindowInSeconds = aws.Int64(int64(d.Get("maximum_batching_window_in_seconds").(int)))
params.MaximumBatchingWindowInSeconds = aws.Int64(int64(d.Get("maximum_batching_window_in_seconds").(int)))
with-joy marked this conversation as resolved.
Show resolved Hide resolved

if eventSourceArn.Service != "sqs" {
if parallelizationFactor, ok := d.GetOk("parallelization_factor"); ok {
params.SetParallelizationFactor(int64(parallelizationFactor.(int)))
}
Expand Down
104 changes: 104 additions & 0 deletions aws/resource_aws_lambda_event_source_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ func TestAccAWSLambdaEventSourceMapping_sqs_withFunctionName(t *testing.T) {
})
}

func TestAccAWSLambdaEventSourceMapping_SQSBatchWindow(t *testing.T) {
with-joy marked this conversation as resolved.
Show resolved Hide resolved
var conf lambda.EventSourceMappingConfiguration

rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lambda_event_source_mapping.test"
batchWindow := int64(0)
batchWindowUpdate := int64(100)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName, batchWindow),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_batching_window_in_seconds", strconv.Itoa(int(batchWindow))),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"enabled", "starting_position"},
},
{
Config: testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName, batchWindowUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_batching_window_in_seconds", strconv.Itoa(int(batchWindowUpdate))),
),
},
},
})
}

func TestAccAWSLambdaEventSourceMapping_kinesis_disappears(t *testing.T) {
var conf lambda.EventSourceMappingConfiguration

Expand Down Expand Up @@ -1451,3 +1488,70 @@ resource "aws_lambda_event_source_mapping" "lambda_event_source_mapping_test" {
}
`, roleName, policyName, attName, streamName, funcName)
}

func testAccAWSLambdaEventSourceMappingConfigSQSBase(rName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %q

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}

resource "aws_iam_role_policy" "test" {
role = aws_iam_role.test.name

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sqs:*"
],
"Resource": "*"
}
]
}
EOF
}

resource "aws_sqs_queue" "test" {
name = %q
}

resource "aws_lambda_function" "test" {
filename = "test-fixtures/lambdatest.zip"
function_name = %q
handler = "exports.example"
role = aws_iam_role.test.arn
runtime = "nodejs12.x"
}
`, rName, rName, rName)
with-joy marked this conversation as resolved.
Show resolved Hide resolved
}

func testAccAWSLambdaEventSourceMappingConfigSqsWithBatchWindow(rName string, batchWindow int64) string {
return testAccAWSLambdaEventSourceMappingConfigSQSBase(rName) + fmt.Sprintf(`
resource "aws_lambda_event_source_mapping" "test" {
batch_size = 10
maximum_batching_window_in_seconds = %d
event_source_arn = aws_sqs_queue.test.arn
enabled = false
function_name = aws_lambda_function.test.arn
}
`, batchWindow)
with-joy marked this conversation as resolved.
Show resolved Hide resolved
}