Skip to content

Commit

Permalink
fix(aws-lambda-tutorial): bugs found while prepping walk-through (#33)
Browse files Browse the repository at this point in the history
* fix(aws-lambda-tutorial): fix route throtlting

* fix(aws-lambda-tutorial): create route53 record

* fix(aws-lambda-tutorial): get region in api
  • Loading branch information
jordan-acosta authored Mar 19, 2024
1 parent 27425d1 commit d834fe9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions aws-lambda-tutorial/components/api-gateway/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "aws_region" "current" {}
19 changes: 19 additions & 0 deletions aws-lambda-tutorial/components/api-gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ module "api_gateway" {
protocol_type = "HTTP"
create_default_stage_access_log_group = true

default_route_settings = {
detailed_metrics_enabled = true
throttling_burst_limit = 100
throttling_rate_limit = 100
}

cors_configuration = {
allow_headers = ["content-type", "x-amz-date", "authorization", "x-api-key", "x-amz-security-token", "x-amz-user-agent"]
allow_methods = ["*"]
Expand All @@ -44,3 +50,16 @@ resource "aws_lambda_permission" "permission" {
principal = "apigateway.amazonaws.com"
source_arn = "${module.api_gateway.apigatewayv2_api_execution_arn}/*/*"
}

resource "aws_route53_record" "custom_domain_record" {
zone_id = var.zone_id
name = var.domain_name
type = "A"
ttl = "60"

alias {
name = module.api_gateway.apigatewayv2_domain_name_configuration[0].target_domain_name
zone_id = module.api_gateway.apigatewayv2_domain_name_configuration[0].hosted_zone_id
evaluate_target_health = false
}
}
6 changes: 5 additions & 1 deletion aws-lambda-tutorial/components/api-gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ variable "name" {
type = string
}

variable "lambda_function_arn" {
type = string
}

variable "domain_name" {
type = string
}
Expand All @@ -10,6 +14,6 @@ variable "domain_name_certificate_arn" {
type = string
}

variable "lambda_function_arn" {
variable "zone_id" {
type = string
}
11 changes: 6 additions & 5 deletions aws-lambda-tutorial/components/api/internal/dynamodb/db.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dynamodb

import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
)

const region = "us-east-1"

var db = dynamodb.New(session.New(), aws.NewConfig().WithRegion(region))

// var db = dynamodb.New(session.NewSession(), aws.NewConfig().WithRegion(region))
var (
region = os.Getenv("AWS_REGION")
db = dynamodb.New(session.New(), aws.NewConfig().WithRegion(region))
)
3 changes: 1 addition & 2 deletions aws-lambda-tutorial/components/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func post(event events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse,
return response(http.StatusUnprocessableEntity, "", err)
}

id := event.PathParameters["id"]
if _, err := strconv.Atoi(id); err != nil {
if _, err := strconv.Atoi(w.ID); err != nil {
return response(http.StatusBadRequest, "", err)
}

Expand Down
4 changes: 0 additions & 4 deletions aws-lambda-tutorial/components/lambda-function/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ variable "function_name" {
variable "image_uri" {
type = string
}

# variable "dynamodb_table_arn" {
# type = string
# }

0 comments on commit d834fe9

Please sign in to comment.