Skip to content

Commit

Permalink
Merge pull request #16113 from raytung/b-aws_lambda_event_source_mapp…
Browse files Browse the repository at this point in the history
…ing-min_values

fix(service/lambda): Corrected EventSourceMapping valid range for maxmum_retry_attempts and maximum_record_age_in_seconds
  • Loading branch information
ewbankkit authored Apr 23, 2021
2 parents c0af974 + 42c9f6f commit 82f9a5f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changelog/16113.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_lambda_event_source_mapping: Support -1 (forever) as a valid value for `maximum_retry_attempts`
```

```release-note:bug
resource/aws_lambda_event_source_mapping: Support -1 (forever) as a valid value for `maximum_record_age_in_seconds`
```
13 changes: 8 additions & 5 deletions aws/resource_aws_lambda_event_source_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ func resourceAwsLambdaEventSourceMapping() *schema.Resource {
"maximum_retry_attempts": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 10000),
Computed: true,
ValidateFunc: validation.IntBetween(-1, 10_000),
},
"maximum_record_age_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(60, 604800),
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.Any(
validation.IntInSlice([]int{-1}),
validation.IntBetween(60, 604_800),
),
},
"bisect_batch_on_function_error": {
Type: schema.TypeBool,
Expand Down
87 changes: 87 additions & 0 deletions aws/resource_aws_lambda_event_source_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,53 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsZero(t *testing.T) {
})
}

func TestAccAWSLambdaEventSourceMapping_MaximumRetryAttemptsNegativeOne(t *testing.T) {
var conf lambda.EventSourceMappingConfiguration
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lambda_event_source_mapping.test"
maximumRetryAttempts := int64(-1)
maximumRetryAttemptsUpdate := int64(100)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, lambda.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttempts),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_retry_attempts", strconv.Itoa(int(maximumRetryAttempts))),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"starting_position",
"starting_position_timestamp",
},
},
{
Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttemptsUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_retry_attempts", strconv.Itoa(int(maximumRetryAttemptsUpdate))),
),
},
{
Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRetryAttempts(rName, maximumRetryAttempts),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_retry_attempts", strconv.Itoa(int(maximumRetryAttempts))),
),
},
},
})
}

func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSeconds(t *testing.T) {
var conf lambda.EventSourceMappingConfiguration
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -550,6 +597,46 @@ func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSeconds(t *testing.T)
})
}

func TestAccAWSLambdaEventSourceMapping_MaximumRecordAgeInSecondsNegativeOne(t *testing.T) {
var conf lambda.EventSourceMappingConfiguration
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_lambda_event_source_mapping.test"
maximumRecordAgeInSeconds := int64(-1)
maximumRecordAgeInSecondsUpdate := int64(3600)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, lambda.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRecordAgeInSeconds(rName, maximumRecordAgeInSeconds),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_record_age_in_seconds", strconv.Itoa(int(maximumRecordAgeInSeconds))),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"starting_position",
"starting_position_timestamp",
},
},
{
Config: testAccAWSLambdaEventSourceMappingConfigKinesisMaximumRecordAgeInSeconds(rName, maximumRecordAgeInSecondsUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaEventSourceMappingExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "maximum_record_age_in_seconds", strconv.Itoa(int(maximumRecordAgeInSecondsUpdate))),
),
},
},
})
}

func TestAccAWSLambdaEventSourceMapping_BisectBatch(t *testing.T) {
var conf lambda.EventSourceMappingConfiguration
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/lambda_event_source_mapping.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ resource "aws_lambda_event_source_mapping" "example" {
* `starting_position` - (Optional) The position in the stream where AWS Lambda should start reading. Must be one of `AT_TIMESTAMP` (Kinesis only), `LATEST` or `TRIM_HORIZON` if getting events from Kinesis, DynamoDB or MSK. Must not be provided if getting events from SQS. More information about these positions can be found in the [AWS DynamoDB Streams API Reference](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_GetShardIterator.html) and [AWS Kinesis API Reference](https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#Kinesis-GetShardIterator-request-ShardIteratorType).
* `starting_position_timestamp` - (Optional) A timestamp in [RFC3339 format](https://tools.ietf.org/html/rfc3339#section-5.8) of the data record which to start reading when using `starting_position` set to `AT_TIMESTAMP`. If a record with this exact timestamp does not exist, the next later record is chosen. If the timestamp is older than the current trim horizon, the oldest available record is chosen.
* `parallelization_factor`: - (Optional) The number of batches to process from each shard concurrently. Only available for stream sources (DynamoDB and Kinesis). Minimum and default of 1, maximum of 10.
* `maximum_retry_attempts`: - (Optional) The maximum number of times to retry when the function returns an error. Only available for stream sources (DynamoDB and Kinesis). Minimum of 0, maximum and default of 10000.
* `maximum_record_age_in_seconds`: - (Optional) The maximum age of a record that Lambda sends to a function for processing. Only available for stream sources (DynamoDB and Kinesis). Minimum of 60, maximum and default of 604800.
* `maximum_retry_attempts`: - (Optional) The maximum number of times to retry when the function returns an error. Only available for stream sources (DynamoDB and Kinesis). Minimum and default of -1 (forever), maximum of 10000.
* `maximum_record_age_in_seconds`: - (Optional) The maximum age of a record that Lambda sends to a function for processing. Only available for stream sources (DynamoDB and Kinesis). Must be either -1 (forever, and the default value) or between 60 and 604800 (inclusive).
* `bisect_batch_on_function_error`: - (Optional) If the function returns an error, split the batch in two and retry. Only available for stream sources (DynamoDB and Kinesis). Defaults to `false`.
* `topics` - (Optional) The name of the Kafka topics. Only available for MSK sources. A single topic name must be specified.
* `destination_config`: - (Optional) An Amazon SQS queue or Amazon SNS topic destination for failed records. Only available for stream sources (DynamoDB and Kinesis). Detailed below.
Expand Down

0 comments on commit 82f9a5f

Please sign in to comment.