This file contains hidden or 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
| resource "aws_iam_role" "apiSQS" { | |
| name = "apigateway_sqs" | |
| assume_role_policy = <<EOF | |
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": "sts:AssumeRole", | |
| "Principal": { |
This file contains hidden or 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
| resource "aws_api_gateway_rest_api" "apiGateway" { | |
| name = "api-gateway-SQS" | |
| description = "POST records to SQS queue" | |
| } | |
| resource "aws_api_gateway_resource" "form_score" { | |
| rest_api_id = aws_api_gateway_rest_api.apiGateway.id | |
| parent_id = aws_api_gateway_rest_api.apiGateway.root_resource_id | |
| path_part = "form-score" | |
| } |
This file contains hidden or 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
| resource "aws_api_gateway_integration" "api" { | |
| rest_api_id = aws_api_gateway_rest_api.apiGateway.id | |
| resource_id = aws_api_gateway_resource.form_score.id | |
| http_method = aws_api_gateway_method.method_form_score.http_method | |
| type = "AWS" | |
| integration_http_method = "POST" | |
| credentials = aws_iam_role.apiSQS.arn | |
| uri = "arn:aws:apigateway:${var.region}:sqs:path/${aws_sqs_queue.queue.name}" | |
| request_parameters = { |
This file contains hidden or 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
| # Mapping SQS Response | |
| resource "aws_api_gateway_method_response" "http200" { | |
| rest_api_id = aws_api_gateway_rest_api.apiGateway.id | |
| resource_id = aws_api_gateway_resource.form_score.id | |
| http_method = aws_api_gateway_method.method_form_score.http_method | |
| status_code = 200 | |
| } | |
| resource "aws_api_gateway_integration_response" "http200" { | |
| rest_api_id = aws_api_gateway_rest_api.apiGateway.id |
This file contains hidden or 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
| resource "aws_api_gateway_deployment" "api" { | |
| rest_api_id = aws_api_gateway_rest_api.apiGateway.id | |
| stage_name = var.environment | |
| depends_on = [ | |
| aws_api_gateway_integration.api, | |
| ] | |
| # Redeploy when there are new updates | |
| triggers = { |
This file contains hidden or 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
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": [ | |
| "sqs:DeleteMessage", | |
| "sqs:ReceiveMessage", | |
| "sqs:GetQueueAttributes" | |
| ], | |
| "Resource": "${sqs_arn}", |
This file contains hidden or 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
| data "archive_file" "lambda_with_dependencies" { | |
| source_dir = "lambda/" | |
| output_path = "lambda/${local.app_name}-${var.lambda_name}.zip" | |
| type = "zip" | |
| } | |
| resource "aws_lambda_function" "lambda_sqs" { | |
| function_name = "${local.app_name}-${var.lambda_name}" | |
| handler = "handler.lambda_handler" | |
| role = aws_iam_role.lambda_exec_role.arn |
This file contains hidden or 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
| resource "aws_lambda_permission" "allows_sqs_to_trigger_lambda" { | |
| statement_id = "AllowExecutionFromSQS" | |
| action = "lambda:InvokeFunction" | |
| function_name = aws_lambda_function.lambda_sqs.function_name | |
| principal = "sqs.amazonaws.com" | |
| source_arn = aws_sqs_queue.queue.arn | |
| } | |
| # Trigger lambda on message to SQS | |
| resource "aws_lambda_event_source_mapping" "event_source_mapping" { |
This file contains hidden or 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
| data "aws_s3_bucket_object" "lambda_sms" { | |
| bucket = var.s3_bucket | |
| key = "lambda-sms.zip" | |
| } | |
| module "lambda_sms" { | |
| source = "[email protected]:DanielDaCosta/lambda-module.git" # Path to your lambda-module | |
| lambda_name = var.lambda_sms | |
| s3_bucket = var.s3_bucket |
This file contains hidden or 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
| image: "python:3.7" | |
| .packages: &package | |
| stage: deploy | |
| before_script: | |
| - apt-get update -y | |
| - apt-get install zip | |
| - pip install awscli | |
| - pip install -r lambda/requirements.txt -t /lambda/package |