-
-
Notifications
You must be signed in to change notification settings - Fork 709
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: event source mapping #103
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8128594
refactor(async): [DVPS-000] add eventbridge async permissions
271ecea
Merge branch 'master' into master
antonbabenko ac539f5
feat(event-source-mapping): wip
e10bb7c
feat: add destination_config block
ee1d8b9
Merge branch 'master' into master
svenlito 7ef4713
Finished examples a bit
antonbabenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Event Source Mapping configuration | ||
|
||
Configuration in this directory creates Lambda Function with event source mapping configuration for SQS queue, Kinesis stream, and DynamoDB table. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
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 | ||
} | ||
|
||
#################################################### | ||
# Lambda Function with event source mapping | ||
#################################################### | ||
|
||
module "lambda_function" { | ||
source = "../../" | ||
|
||
function_name = "${random_pet.this.id}-lambda-event-source-mapping" | ||
handler = "index.lambda_handler" | ||
runtime = "python3.8" | ||
|
||
source_path = "${path.module}/../fixtures/python3.8-app1" | ||
|
||
event_source_mapping = { | ||
sqs = { | ||
event_source_arn = aws_sqs_queue.this.arn | ||
} | ||
dynamodb = { | ||
event_source_arn = aws_dynamodb_table.this.stream_arn | ||
starting_position = "LATEST" | ||
# This can be created but it won't be updated/removed. To be reviewed in the future. | ||
# destination_config = { | ||
# on_failure = { | ||
# destination_arn = aws_sqs_queue.failure.arn | ||
# } | ||
# } | ||
} | ||
kinesis = { | ||
event_source_arn = aws_kinesis_stream.this.arn | ||
starting_position = "LATEST" | ||
} | ||
} | ||
|
||
allowed_triggers = { | ||
sqs = { | ||
principal = "sqs.amazonaws.com" | ||
source_arn = aws_sqs_queue.this.arn | ||
} | ||
dynamodb = { | ||
principal = "dynamodb.amazonaws.com" | ||
source_arn = aws_dynamodb_table.this.stream_arn | ||
} | ||
kinesis = { | ||
principal = "kinesis.amazonaws.com" | ||
source_arn = aws_kinesis_stream.this.arn | ||
} | ||
} | ||
|
||
create_current_version_allowed_triggers = false | ||
|
||
# Allow failures to be sent to SQS queue | ||
attach_policy_statements = true | ||
policy_statements = { | ||
sqs_failure = { | ||
effect = "Allow", | ||
actions = ["sqs:SendMessage"], | ||
resources = [aws_sqs_queue.failure.arn] | ||
} | ||
} | ||
|
||
attach_policies = true | ||
number_of_policies = 3 | ||
|
||
policies = [ | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole", | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", | ||
] | ||
} | ||
|
||
################## | ||
# Extra resources | ||
################## | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_sqs_queue" "this" { | ||
name = random_pet.this.id | ||
} | ||
|
||
resource "aws_dynamodb_table" "this" { | ||
name = random_pet.this.id | ||
billing_mode = "PAY_PER_REQUEST" | ||
hash_key = "UserId" | ||
range_key = "GameTitle" | ||
stream_view_type = "NEW_AND_OLD_IMAGES" | ||
stream_enabled = true | ||
|
||
attribute { | ||
name = "UserId" | ||
type = "S" | ||
} | ||
|
||
attribute { | ||
name = "GameTitle" | ||
type = "S" | ||
} | ||
} | ||
|
||
resource "aws_kinesis_stream" "this" { | ||
name = random_pet.this.id | ||
shard_count = 1 | ||
} | ||
|
||
resource "aws_sqs_queue" "failure" { | ||
name = "${random_pet.this.id}-failure" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Lambda Function | ||
output "this_lambda_function_arn" { | ||
description = "The ARN of the Lambda Function" | ||
value = module.lambda_function.this_lambda_function_arn | ||
} | ||
|
||
output "this_lambda_function_invoke_arn" { | ||
description = "The Invoke ARN of the Lambda Function" | ||
value = module.lambda_function.this_lambda_function_invoke_arn | ||
} | ||
|
||
output "this_lambda_function_name" { | ||
description = "The name of the Lambda Function" | ||
value = module.lambda_function.this_lambda_function_name | ||
} | ||
|
||
output "this_lambda_function_qualified_arn" { | ||
description = "The ARN identifying your Lambda Function Version" | ||
value = module.lambda_function.this_lambda_function_qualified_arn | ||
} | ||
|
||
output "this_lambda_function_version" { | ||
description = "Latest published version of Lambda Function" | ||
value = module.lambda_function.this_lambda_function_version | ||
} | ||
|
||
output "this_lambda_function_last_modified" { | ||
description = "The date Lambda Function resource was last modified" | ||
value = module.lambda_function.this_lambda_function_last_modified | ||
} | ||
|
||
output "this_lambda_function_kms_key_arn" { | ||
description = "The ARN for the KMS encryption key of Lambda Function" | ||
value = module.lambda_function.this_lambda_function_kms_key_arn | ||
} | ||
|
||
output "this_lambda_function_source_code_hash" { | ||
description = "Base64-encoded representation of raw SHA-256 sum of the zip file" | ||
value = module.lambda_function.this_lambda_function_source_code_hash | ||
} | ||
|
||
output "this_lambda_function_source_code_size" { | ||
description = "The size in bytes of the function .zip file" | ||
value = module.lambda_function.this_lambda_function_source_code_size | ||
} | ||
|
||
# Lambda Event Source Mapping | ||
output "this_lambda_event_source_mapping_function_arn" { | ||
description = "The the ARN of the Lambda function the event source mapping is sending events to" | ||
value = module.lambda_function.this_lambda_event_source_mapping_function_arn | ||
} | ||
|
||
output "this_lambda_event_source_mapping_state" { | ||
description = "The state of the event source mapping" | ||
value = module.lambda_function.this_lambda_event_source_mapping_state | ||
} | ||
|
||
output "this_lambda_event_source_mapping_state_transition_reason" { | ||
description = "The reason the event source mapping is in its current state" | ||
value = module.lambda_function.this_lambda_event_source_mapping_state_transition_reason | ||
} | ||
|
||
output "this_lambda_event_source_mapping_uuid" { | ||
description = "The UUID of the created event source mapping" | ||
value = module.lambda_function.this_lambda_event_source_mapping_uuid | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_version = ">= 0.12.6" | ||
|
||
required_providers { | ||
aws = ">= 3.27" | ||
random = ">= 2" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svenlito There seems to be a bug somewhere related to the editing of
destination_config
argument of this resource (once created, it won't be removed/updated via this resource). I couldn't figure out the solution, so just disabled this feature for now.