Skip to content

Commit

Permalink
feat: Support maximum concurrency of Lambda with SQS as an event sour…
Browse files Browse the repository at this point in the history
…ce (#402)

Co-authored-by: Anton Babenko <anton@antonbabenko.com>
Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
  • Loading branch information
3 people committed Apr 3, 2023
1 parent 0003c43 commit 268975c
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.77.0
rev: v1.77.1
hooks:
- id: terraform_fmt
- id: terraform_validate
Expand Down
1 change: 0 additions & 1 deletion examples/alias/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/async/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/code-signing/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/container-image/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/deploy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
35 changes: 25 additions & 10 deletions examples/event-source-mapping/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true

skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
skip_requesting_account_id = true
}

data "aws_availability_zones" "available" {}

locals {
vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
}

####################################################
# Lambda Function with event source mapping
####################################################
Expand All @@ -20,12 +27,15 @@ module "lambda_function" {
handler = "index.lambda_handler"
runtime = "python3.8"

source_path = "${path.module}/../fixtures/python3.8-app1"
source_path = "${path.module}/../fixtures/python3.8-app1/index.py"

event_source_mapping = {
sqs = {
event_source_arn = aws_sqs_queue.this.arn
function_response_types = ["ReportBatchItemFailures"]
scaling_config = {
maximum_concurrency = 20
}
}
dynamodb = {
event_source_arn = aws_dynamodb_table.this.stream_arn
Expand Down Expand Up @@ -216,21 +226,26 @@ resource "aws_kinesis_stream" "this" {
}

# Amazon MQ
data "aws_vpc" "default" {
default = true
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"

name = random_pet.this.id
cidr = local.vpc_cidr

azs = local.azs
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]

data "aws_security_group" "default" {
vpc_id = data.aws_vpc.default.id
name = "default"
enable_nat_gateway = false
}

resource "aws_mq_broker" "this" {
broker_name = random_pet.this.id
engine_type = "RabbitMQ"
engine_version = "3.8.11"
engine_version = "3.10.10"
host_instance_type = "mq.t3.micro"
security_groups = [data.aws_security_group.default.id]
security_groups = [module.vpc.default_security_group_id]
subnet_ids = slice(module.vpc.public_subnets, 0, 1)

user {
username = random_pet.this.id
Expand Down
2 changes: 0 additions & 2 deletions examples/multiple-regions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand All @@ -14,7 +13,6 @@ provider "aws" {
alias = "us-east-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ provider "aws" {
# region = "us-east-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/triggers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/with-efs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/with-vpc-s3-endpoint/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
1 change: 0 additions & 1 deletion examples/with-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ provider "aws" {
region = "eu-west-1"

# Make it faster by skipping something
skip_get_ec2_platforms = true
skip_metadata_api_check = true
skip_region_validation = true
skip_credentials_validation = true
Expand Down
8 changes: 8 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ resource "aws_lambda_event_source_mapping" "this" {
}
}

dynamic "scaling_config" {
for_each = try([each.value.scaling_config], [])
content {
maximum_concurrency = try(scaling_config.value.maximum_concurrency, null)
}
}


dynamic "self_managed_event_source" {
for_each = try(each.value.self_managed_event_source, [])
content {
Expand Down

0 comments on commit 268975c

Please sign in to comment.