diff --git a/terraform/modules/apigw/main.tf b/terraform/modules/apigw/main.tf index c12a4d1..d7a6618 100644 --- a/terraform/modules/apigw/main.tf +++ b/terraform/modules/apigw/main.tf @@ -17,7 +17,7 @@ resource "aws_api_gateway_resource" "this" { resource "aws_api_gateway_method" "this" { rest_api_id = aws_api_gateway_rest_api.this.id resource_id = aws_api_gateway_resource.this.id - http_method = "ANY" + http_method = "GET" authorization = "NONE" } @@ -25,9 +25,10 @@ resource "aws_api_gateway_integration" "this" { rest_api_id = aws_api_gateway_rest_api.this.id resource_id = aws_api_gateway_resource.this.id http_method = aws_api_gateway_method.this.http_method - integration_http_method = "ANY" + integration_http_method = "POST" type = "AWS_PROXY" - uri = var.lambda_function_arn + # uri = var.lambda_function_arn + uri = var.sqs_arn } resource "aws_api_gateway_deployment" "this" { diff --git a/terraform/organization/apigw.tf b/terraform/organization/apigw.tf index c74359d..c974342 100644 --- a/terraform/organization/apigw.tf +++ b/terraform/organization/apigw.tf @@ -11,9 +11,9 @@ module "apigw" { name = "AWSAPIGateway-g3" description = "..." - lambda_function_arn = module.lambda["lambda"].lambda_function_arn - lambda_function_name = module.lambda["lambda"].lambda_function_name - lambda_source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}" + # lambda_function_arn = module.lambda["lambda"].lambda_function_arn + # lambda_function_name = module.lambda["lambda"].lambda_function_name + # lambda_source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}" tags = { name = "Api Gateway" diff --git a/terraform/organization/lambda.tf b/terraform/organization/lambda.tf index 465f52b..dcdb4bb 100644 --- a/terraform/organization/lambda.tf +++ b/terraform/organization/lambda.tf @@ -16,6 +16,7 @@ module "lambda" { package = each.value.package iam_role = each.value.role - vpc_subnet_ids = module.vpc.private_subnets + # vpc_subnet_ids = module.vpc.private_subnets + vpc_subnet_ids = module.vpc.public_subnets vpc_security_group_ids = [module.vpc.default_security_group_id] } diff --git a/terraform/organization/locals.tf b/terraform/organization/locals.tf index 3390935..976b902 100644 --- a/terraform/organization/locals.tf +++ b/terraform/organization/locals.tf @@ -26,6 +26,10 @@ locals { www-website = { bucket_name = "www.${local.bucket_name}" } + + logs = { + bucket_name = "${local.bucket_name}-logs" + } } lambdas = { diff --git a/terraform/organization/s3.tf b/terraform/organization/s3.tf index 2c276cf..d410ae4 100644 --- a/terraform/organization/s3.tf +++ b/terraform/organization/s3.tf @@ -6,8 +6,9 @@ module "s3" { aws = aws.aws } - bucket_name = each.value.bucket_name - objects = try(each.value.objects, {}) + bucket_name = each.value.bucket_name + objects = try(each.value.objects, {}) + bucket_acl = "public-read" } resource "aws_s3_object" "this" { diff --git a/terraform/resources/lambda/lambda.zip b/terraform/resources/lambda/lambda.zip index bbb9f1b..37185da 100644 Binary files a/terraform/resources/lambda/lambda.zip and b/terraform/resources/lambda/lambda.zip differ diff --git a/terraform/resources/lambda/lambda_handler.py b/terraform/resources/lambda/lambda_handler.py index 9acf903..86165b2 100644 --- a/terraform/resources/lambda/lambda_handler.py +++ b/terraform/resources/lambda/lambda_handler.py @@ -1,12 +1,28 @@ -def main (event, context): - print ("In lambda handler") +import boto3 +import json - resp = { - "statusCode": 200, - "headers": { - "Access-Control-Allow-Origin": "*", - }, - "body": "El lab ha sido finalizado correctamente" - } - return resp \ No newline at end of file +def main(event, context): + client = boto3.client('dynamodb') + + client.put_item(Item={ + "id": { + "N": "1" + }, + "stock": { + "N": "2212" + }, + }, + TableName='AWSDynamoDB-g3') + + print ("In lambda handler") + + resp = { + "statusCode": 200, + "headers": { + "Access-Control-Allow-Origin": "*", + }, + "body": "Se cargó el elemento correctamente" + } + + return resp