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

feat: Support maximum concurrency of Lambda with SQS as an event source #402

Merged
merged 4 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed due to
image

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was throwing an error around a specific version of python being required. Changing to point directly to the individual file fixed that. I don't believe that affects the intent of this example


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" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any default VPCs, so added a bare bones one to make it work for the RabbitMQ requirements

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is almost at EOS so updated to latest recommended by AWS

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