diff --git a/aws-lambda-tutorial/components/api-gateway/.terraform.lock.hcl b/aws-lambda-tutorial/components/api-gateway/.terraform.lock.hcl new file mode 100644 index 0000000..a2ba206 --- /dev/null +++ b/aws-lambda-tutorial/components/api-gateway/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.41.0" + constraints = ">= 4.0.0" + hashes = [ + "h1:DiX7N35G2NUQRyRGy90+gyePnhP4w77f8LrJUronotE=", + "zh:0553331a6287c146353b6daf6f71987d8c000f407b5e29d6e004ea88faec2e67", + "zh:1a11118984bb2950e8ee7ef17b0f91fc9eb4a42c8e7a9cafd7eb4aca771d06e4", + "zh:236fedd266d152a8233a7fe27ffdd99ca27d9e66a9618a988a4c3da1ac24a33f", + "zh:34bc482ea04cf30d4d216afa55eecf66854e1acf93892cb28a6b5af91d43c9b7", + "zh:39d7eb15832fe339bf46e3bab9852280762a1817bf1afc459eecd430e20e3ad5", + "zh:39fb07429c51556b05170ec2b6bd55e2487adfe1606761eaf1f2a43c4bb20e47", + "zh:71d7cd3013e2f3fa0f65194af29ee6f5fa905e0df2b72b723761dc953f4512ea", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9b271ae12394e7e2ce6da568b42226a146e90fd705e02a670fcb93618c4aa19f", + "zh:a884dd978859d001709681f9513ba0fbb0753d1d459a7f3434ecc5f1b8699c49", + "zh:b8c3c7dc10ae4f6143168042dcf8dee63527b103cc37abc238ea06150af38b6e", + "zh:ba94ffe0893ad60c0b70c402e163b4df2cf417e93474a9cc1a37535bba18f22d", + "zh:d5ba851d971ff8d796afd9a100acf55eaac0c197c6ab779787797ce66f419f0e", + "zh:e8c090d0c4f730c4a610dc4f0c22b177a0376d6f78679fc3f1d557b469e656f4", + "zh:ed7623acde26834672969dcb5befdb62900d9f216d32e7478a095d2b040a0ea7", + ] +} diff --git a/aws-lambda-tutorial/components/api-gateway/main.tf b/aws-lambda-tutorial/components/api-gateway/main.tf new file mode 100644 index 0000000..083cbfd --- /dev/null +++ b/aws-lambda-tutorial/components/api-gateway/main.tf @@ -0,0 +1,46 @@ +locals { + integrations = { + "GET /widgets/{id}" = { + lambda_arn = var.lambda_function_arn + payload_format_version = "2.0" + timeout_milliseconds = 12000 + } + + "POST /widgets" = { + lambda_arn = var.lambda_function_arn + payload_format_version = "2.0" + timeout_milliseconds = 12000 + } + + // "DELETE /widgets/{id}" = { + // lambda_arn = var.lambda_function_arn + // payload_format_version = "2.0" + // timeout_milliseconds = 12000 + // } + } +} + +module "api_gateway" { + source = "terraform-aws-modules/apigateway-v2/aws" + + name = var.name + integrations = local.integrations + domain_name = var.domain_name + domain_name_certificate_arn = var.domain_name_certificate_arn + protocol_type = "HTTP" + create_default_stage_access_log_group = true + + cors_configuration = { + allow_headers = ["content-type", "x-amz-date", "authorization", "x-api-key", "x-amz-security-token", "x-amz-user-agent"] + allow_methods = ["*"] + allow_origins = ["*"] + } +} + +resource "aws_lambda_permission" "permission" { + function_name = element(split(":", var.lambda_function_arn), length(split(":", var.lambda_function_arn)) - 1) + statement_id = "AllowExecutionFromAPIGateway" + action = "lambda:InvokeFunction" + principal = "apigateway.amazonaws.com" + source_arn = "${module.api_gateway.apigatewayv2_api_execution_arn}/*/*" +} diff --git a/aws-lambda-tutorial/components/api-gateway/variables.tf b/aws-lambda-tutorial/components/api-gateway/variables.tf new file mode 100644 index 0000000..85320c5 --- /dev/null +++ b/aws-lambda-tutorial/components/api-gateway/variables.tf @@ -0,0 +1,15 @@ +variable "name" { + type = string +} + +variable "domain_name" { + type = string +} + +variable "domain_name_certificate_arn" { + type = string +} + +variable "lambda_function_arn" { + type = string +} diff --git a/aws-lambda-tutorial/components/api-gateway/versions.tf b/aws-lambda-tutorial/components/api-gateway/versions.tf new file mode 100644 index 0000000..4f6d0b8 --- /dev/null +++ b/aws-lambda-tutorial/components/api-gateway/versions.tf @@ -0,0 +1,12 @@ +terraform { + required_version = ">= 1.3.7" + + backend "s3" {} + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.0" + } + } +} diff --git a/aws-lambda-tutorial/components/api/Dockerfile b/aws-lambda-tutorial/components/api/Dockerfile new file mode 100644 index 0000000..1a46a24 --- /dev/null +++ b/aws-lambda-tutorial/components/api/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.22.1-alpine3.19 as build + +WORKDIR /app +COPY ./ ./ +RUN go mod download +COPY *.go ./ +RUN CGO_ENABLED=0 GOOS=linux go build -o api + +FROM alpine:3.19 +COPY --from=build /app/api /main +ENTRYPOINT ["/main"] diff --git a/aws-lambda-tutorial/components/api/go.mod b/aws-lambda-tutorial/components/api/go.mod new file mode 100644 index 0000000..ed91ed8 --- /dev/null +++ b/aws-lambda-tutorial/components/api/go.mod @@ -0,0 +1,10 @@ +module github.com/nuonco/guides/aws-lambda-tutorial/components/api + +go 1.22.1 + +require ( + github.com/aws/aws-lambda-go v1.46.0 + github.com/aws/aws-sdk-go v1.51.2 +) + +require github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/aws-lambda-tutorial/components/api/go.sum b/aws-lambda-tutorial/components/api/go.sum new file mode 100644 index 0000000..e9a7bef --- /dev/null +++ b/aws-lambda-tutorial/components/api/go.sum @@ -0,0 +1,21 @@ +github.com/aws/aws-lambda-go v1.46.0 h1:UWVnvh2h2gecOlFhHQfIPQcD8pL/f7pVCutmFl+oXU8= +github.com/aws/aws-lambda-go v1.46.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= +github.com/aws/aws-sdk-go v1.51.2 h1:Ruwgz5aqIXin5Yfcgc+PCzoqW5tEGb9aDL/JWDsre7k= +github.com/aws/aws-sdk-go v1.51.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/aws-lambda-tutorial/components/api/internal/dynamodb/db.go b/aws-lambda-tutorial/components/api/internal/dynamodb/db.go new file mode 100644 index 0000000..8431b19 --- /dev/null +++ b/aws-lambda-tutorial/components/api/internal/dynamodb/db.go @@ -0,0 +1,13 @@ +package dynamodb + +import ( + "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)) diff --git a/aws-lambda-tutorial/components/api/internal/dynamodb/get_item.go b/aws-lambda-tutorial/components/api/internal/dynamodb/get_item.go new file mode 100644 index 0000000..e9a7a74 --- /dev/null +++ b/aws-lambda-tutorial/components/api/internal/dynamodb/get_item.go @@ -0,0 +1,35 @@ +package dynamodb + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/dynamodb" + "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" + "github.com/nuonco/guides/aws-lambda-tutorial/components/api/internal/widget" +) + +func GetItem(id, table string) (*widget.Widget, error) { + input := &dynamodb.GetItemInput{ + TableName: aws.String(table), + Key: map[string]*dynamodb.AttributeValue{ + "ID": { + N: aws.String(id), + }, + }, + } + + result, err := db.GetItem(input) + if err != nil { + return nil, err + } + if result.Item == nil { + return nil, nil + } + + widget := new(widget.Widget) + err = dynamodbattribute.UnmarshalMap(result.Item, widget) + if err != nil { + return nil, err + } + + return widget, nil +} diff --git a/aws-lambda-tutorial/components/api/internal/dynamodb/put_item.go b/aws-lambda-tutorial/components/api/internal/dynamodb/put_item.go new file mode 100644 index 0000000..2b1e0f1 --- /dev/null +++ b/aws-lambda-tutorial/components/api/internal/dynamodb/put_item.go @@ -0,0 +1,24 @@ +package dynamodb + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/dynamodb" +) + +func PutItem(id, table string) error { + input := &dynamodb.PutItemInput{ + TableName: aws.String(table), + Item: map[string]*dynamodb.AttributeValue{ + "ID": { + N: aws.String(id), + }, + }, + } + + _, err := db.PutItem(input) + if err != nil { + return err + } + + return nil +} diff --git a/aws-lambda-tutorial/components/api/internal/logging/logger.go b/aws-lambda-tutorial/components/api/internal/logging/logger.go new file mode 100644 index 0000000..2eba488 --- /dev/null +++ b/aws-lambda-tutorial/components/api/internal/logging/logger.go @@ -0,0 +1,8 @@ +package logging + +import ( + "log" + "os" +) + +var DefaultLogger = log.New(os.Stdout, "", log.Llongfile) diff --git a/aws-lambda-tutorial/components/api/internal/widget/main.go b/aws-lambda-tutorial/components/api/internal/widget/main.go new file mode 100644 index 0000000..5d80541 --- /dev/null +++ b/aws-lambda-tutorial/components/api/internal/widget/main.go @@ -0,0 +1,5 @@ +package widget + +type Widget struct { + ID string `json:"id"` +} diff --git a/aws-lambda-tutorial/components/api/main.go b/aws-lambda-tutorial/components/api/main.go new file mode 100644 index 0000000..028a2ed --- /dev/null +++ b/aws-lambda-tutorial/components/api/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" + "strconv" + + "github.com/aws/aws-lambda-go/events" + "github.com/aws/aws-lambda-go/lambda" + "github.com/nuonco/guides/aws-lambda-tutorial/components/api/internal/dynamodb" + "github.com/nuonco/guides/aws-lambda-tutorial/components/api/internal/logging" + "github.com/nuonco/guides/aws-lambda-tutorial/components/api/internal/widget" +) + +var logger = logging.DefaultLogger + +func response(statusCode int, body string, err error) (events.APIGatewayProxyResponse, error) { + if err != nil { + logger.Println(err.Error()) + body = http.StatusText(statusCode) + } + + return events.APIGatewayProxyResponse{ + StatusCode: statusCode, + Body: body, + }, err +} + +func get(event events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) { + id := event.PathParameters["id"] + if _, err := strconv.Atoi(id); err != nil { + return response(http.StatusBadRequest, "", err) + } + + widget, err := dynamodb.GetItem(id, "widgets") + if err != nil { + return response(http.StatusInternalServerError, "", err) + } + if widget == nil { + return response(http.StatusNotFound, "", err) + } + + js, err := json.Marshal(widget) + if err != nil { + return response(http.StatusInternalServerError, "", err) + } + + return response(http.StatusOK, string(js), nil) +} + +func post(event events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) { + w := widget.Widget{} + err := json.Unmarshal([]byte(event.Body), &w) + if err != nil { + return response(http.StatusUnprocessableEntity, "", err) + } + + id := event.PathParameters["id"] + if _, err := strconv.Atoi(id); err != nil { + return response(http.StatusBadRequest, "", err) + } + + err = dynamodb.PutItem(w.ID, "widgets") + if err != nil { + return response(http.StatusInternalServerError, "", err) + } + + return response(http.StatusOK, "", nil) +} + +func router(event events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) { + logger.Printf("event: %+v", event) + method := event.RequestContext.HTTP.Method + switch method { + case "GET": + return get(event) + case "POST": + return post(event) + default: + return response(http.StatusMethodNotAllowed, "", fmt.Errorf("method %s not allowed", method)) + } +} + +func main() { + lambda.Start(router) +} diff --git a/aws-lambda-tutorial/components/certificate/.terraform.lock.hcl b/aws-lambda-tutorial/components/certificate/.terraform.lock.hcl new file mode 100644 index 0000000..8c23ec1 --- /dev/null +++ b/aws-lambda-tutorial/components/certificate/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.30.0" + constraints = ">= 4.40.0" + hashes = [ + "h1:ZsaqSoi0hx+GXUK1AaCwoHx+XYgiZY2JZX2UZ6kVvH4=", + "zh:0ac576f2278c6d3fead05fbb136df87e399ec065edeef56c054fa2f3ac465390", + "zh:1ef592d293cac2f35c37c4d23cb5f9e8b34713e24585cedaf5874d024712d9fd", + "zh:21d8412d5cec5e7e9a2199089d95287c5882f4db0e3b820e4f7760242bfa83b2", + "zh:29bcc5616d579cd389b9c43a1922e7eafe68c8ca1b0f13e91b9e0a38d59c8b89", + "zh:3afed6c066524eccabab25ba83af5d2b5b46e6187968284da0cb49a01002e0e8", + "zh:4745d71ca72a6dcf819afe8065fcd8883c8434cdcfcfdc9ab3a4722fd611b437", + "zh:486701b188b4a6a656a3f23b704dc53f4766164c23368542de36622f28b3248d", + "zh:56cd5846b35cd405f63cf33b1fdfe6e99ff19f893aaacedc6e9245c563397173", + "zh:5d1d4806c15c49755c8e73dd590471c43ae84a3ded8c54b0e397ad6336fba6e5", + "zh:7df03941001c14ce255a6f4f5c2edd275fb45a9d7cd316229eef6558f79c0149", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:b0c1732d3a32630bc17d8da29662b16e346b1739ff72273e6169f9f5a968cb82", + "zh:ce9888a63f6a6a8786499fa3e2350b13f6b87410561122799871d50a3cf07604", + "zh:d336271de465e9ed48bce89ce97a874e3d9e2916712e3359d419c811365d75ee", + "zh:e528275339aea59021ec810ee74220ce328181ee38f4ce6c7b1efb2db9dca56f", + ] +} diff --git a/aws-lambda-tutorial/components/certificate/main.tf b/aws-lambda-tutorial/components/certificate/main.tf new file mode 100644 index 0000000..7eaf4c0 --- /dev/null +++ b/aws-lambda-tutorial/components/certificate/main.tf @@ -0,0 +1,9 @@ +module "certificate" { + source = "terraform-aws-modules/acm/aws" + version = "~> 4.0" + + domain_name = var.domain_name + zone_id = var.zone_id + validation_method = "DNS" + wait_for_validation = false +} diff --git a/aws-lambda-tutorial/components/certificate/outputs.tf b/aws-lambda-tutorial/components/certificate/outputs.tf new file mode 100644 index 0000000..c612898 --- /dev/null +++ b/aws-lambda-tutorial/components/certificate/outputs.tf @@ -0,0 +1,3 @@ +output "public_domain_certificate_arn" { + value = module.certificate.acm_certificate_arn +} diff --git a/aws-lambda-tutorial/components/certificate/variables.tf b/aws-lambda-tutorial/components/certificate/variables.tf new file mode 100644 index 0000000..08ea503 --- /dev/null +++ b/aws-lambda-tutorial/components/certificate/variables.tf @@ -0,0 +1,7 @@ +variable "domain_name" { + type = string +} + +variable "zone_id" { + type = string +} diff --git a/aws-lambda-tutorial/components/dynamodb-table/.terraform.lock.hcl b/aws-lambda-tutorial/components/dynamodb-table/.terraform.lock.hcl new file mode 100644 index 0000000..a2ba206 --- /dev/null +++ b/aws-lambda-tutorial/components/dynamodb-table/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.41.0" + constraints = ">= 4.0.0" + hashes = [ + "h1:DiX7N35G2NUQRyRGy90+gyePnhP4w77f8LrJUronotE=", + "zh:0553331a6287c146353b6daf6f71987d8c000f407b5e29d6e004ea88faec2e67", + "zh:1a11118984bb2950e8ee7ef17b0f91fc9eb4a42c8e7a9cafd7eb4aca771d06e4", + "zh:236fedd266d152a8233a7fe27ffdd99ca27d9e66a9618a988a4c3da1ac24a33f", + "zh:34bc482ea04cf30d4d216afa55eecf66854e1acf93892cb28a6b5af91d43c9b7", + "zh:39d7eb15832fe339bf46e3bab9852280762a1817bf1afc459eecd430e20e3ad5", + "zh:39fb07429c51556b05170ec2b6bd55e2487adfe1606761eaf1f2a43c4bb20e47", + "zh:71d7cd3013e2f3fa0f65194af29ee6f5fa905e0df2b72b723761dc953f4512ea", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9b271ae12394e7e2ce6da568b42226a146e90fd705e02a670fcb93618c4aa19f", + "zh:a884dd978859d001709681f9513ba0fbb0753d1d459a7f3434ecc5f1b8699c49", + "zh:b8c3c7dc10ae4f6143168042dcf8dee63527b103cc37abc238ea06150af38b6e", + "zh:ba94ffe0893ad60c0b70c402e163b4df2cf417e93474a9cc1a37535bba18f22d", + "zh:d5ba851d971ff8d796afd9a100acf55eaac0c197c6ab779787797ce66f419f0e", + "zh:e8c090d0c4f730c4a610dc4f0c22b177a0376d6f78679fc3f1d557b469e656f4", + "zh:ed7623acde26834672969dcb5befdb62900d9f216d32e7478a095d2b040a0ea7", + ] +} diff --git a/aws-lambda-tutorial/components/dynamodb-table/main.tf b/aws-lambda-tutorial/components/dynamodb-table/main.tf new file mode 100644 index 0000000..a25e831 --- /dev/null +++ b/aws-lambda-tutorial/components/dynamodb-table/main.tf @@ -0,0 +1,13 @@ +module "dynamodb_table" { + source = "terraform-aws-modules/dynamodb-table/aws" + + name = var.name + hash_key = var.hash_key + + attributes = [ + { + name = "ID" + type = "N" + }, + ] +} diff --git a/aws-lambda-tutorial/components/dynamodb-table/outputs.tf b/aws-lambda-tutorial/components/dynamodb-table/outputs.tf new file mode 100644 index 0000000..e027fe8 --- /dev/null +++ b/aws-lambda-tutorial/components/dynamodb-table/outputs.tf @@ -0,0 +1,3 @@ +output "dynamodb_table_arn" { + value = module.dynamodb_table.dynamodb_table_arn +} diff --git a/aws-lambda-tutorial/components/dynamodb-table/variables.tf b/aws-lambda-tutorial/components/dynamodb-table/variables.tf new file mode 100644 index 0000000..b035812 --- /dev/null +++ b/aws-lambda-tutorial/components/dynamodb-table/variables.tf @@ -0,0 +1,7 @@ +variable "name" { + type = string +} + +variable "hash_key" { + type = string +} diff --git a/aws-lambda-tutorial/components/dynamodb-table/versions.tf b/aws-lambda-tutorial/components/dynamodb-table/versions.tf new file mode 100644 index 0000000..4f6d0b8 --- /dev/null +++ b/aws-lambda-tutorial/components/dynamodb-table/versions.tf @@ -0,0 +1,12 @@ +terraform { + required_version = ">= 1.3.7" + + backend "s3" {} + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.0" + } + } +} diff --git a/aws-lambda-tutorial/components/lambda-function/.terraform.lock.hcl b/aws-lambda-tutorial/components/lambda-function/.terraform.lock.hcl new file mode 100644 index 0000000..127a09b --- /dev/null +++ b/aws-lambda-tutorial/components/lambda-function/.terraform.lock.hcl @@ -0,0 +1,85 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.41.0" + constraints = ">= 4.0.0, >= 5.32.0" + hashes = [ + "h1:DiX7N35G2NUQRyRGy90+gyePnhP4w77f8LrJUronotE=", + "zh:0553331a6287c146353b6daf6f71987d8c000f407b5e29d6e004ea88faec2e67", + "zh:1a11118984bb2950e8ee7ef17b0f91fc9eb4a42c8e7a9cafd7eb4aca771d06e4", + "zh:236fedd266d152a8233a7fe27ffdd99ca27d9e66a9618a988a4c3da1ac24a33f", + "zh:34bc482ea04cf30d4d216afa55eecf66854e1acf93892cb28a6b5af91d43c9b7", + "zh:39d7eb15832fe339bf46e3bab9852280762a1817bf1afc459eecd430e20e3ad5", + "zh:39fb07429c51556b05170ec2b6bd55e2487adfe1606761eaf1f2a43c4bb20e47", + "zh:71d7cd3013e2f3fa0f65194af29ee6f5fa905e0df2b72b723761dc953f4512ea", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9b271ae12394e7e2ce6da568b42226a146e90fd705e02a670fcb93618c4aa19f", + "zh:a884dd978859d001709681f9513ba0fbb0753d1d459a7f3434ecc5f1b8699c49", + "zh:b8c3c7dc10ae4f6143168042dcf8dee63527b103cc37abc238ea06150af38b6e", + "zh:ba94ffe0893ad60c0b70c402e163b4df2cf417e93474a9cc1a37535bba18f22d", + "zh:d5ba851d971ff8d796afd9a100acf55eaac0c197c6ab779787797ce66f419f0e", + "zh:e8c090d0c4f730c4a610dc4f0c22b177a0376d6f78679fc3f1d557b469e656f4", + "zh:ed7623acde26834672969dcb5befdb62900d9f216d32e7478a095d2b040a0ea7", + ] +} + +provider "registry.terraform.io/hashicorp/external" { + version = "2.3.3" + constraints = ">= 1.0.0" + hashes = [ + "h1:gShzO1rJtADK9tDZMvMgjciVAzsBh39LNjtThCwX1Hg=", + "zh:03d81462f9578ec91ce8e26f887e34151eda0e100f57e9772dbea86363588239", + "zh:37ec2a20f6a3ec3a0fd95d3f3de26da6cb9534b30488bc45723e118a0911c0d8", + "zh:4eb5b119179539f2749ce9de0e1b9629d025990f062f4f4dddc161562bb89d37", + "zh:5a31bb58414f41bee5e09b939012df5b88654120b0238a89dfd6691ba197619a", + "zh:6221a05e52a6a2d4f520ffe7cbc741f4f6080e0855061b0ed54e8be4a84eb9b7", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:8bb068496b4679bef625e4710d9f3432e301c3a56602271f04e60eadf7f8a94c", + "zh:94742aa5378bab626ce34f79bcef6a373e4f86ea7a8b762e9f71270a899e0d00", + "zh:a485831b5a525cd8f40e8982fa37da40ff70b1ae092c8b755fcde123f0b1238d", + "zh:a647ff16d071eabcabd87ea8183eb90a775a0294ddd735d742075d62fff09193", + "zh:b74710c5954aaa3faf262c18d36a8c2407862d9f842c63e7fa92fa4de3d29df6", + "zh:fa73d83edc92af2e551857594c2232ba6a9e3603ad34b0a5940865202c08d8d7", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.5.1" + constraints = ">= 1.0.0" + hashes = [ + "h1:/GAVA/xheGQcbOZEq0qxANOg+KVLCA7Wv8qluxhTjhU=", + "zh:0af29ce2b7b5712319bf6424cb58d13b852bf9a777011a545fac99c7fdcdf561", + "zh:126063ea0d79dad1f68fa4e4d556793c0108ce278034f101d1dbbb2463924561", + "zh:196bfb49086f22fd4db46033e01655b0e5e036a5582d250412cc690fa7995de5", + "zh:37c92ec084d059d37d6cffdb683ccf68e3a5f8d2eb69dd73c8e43ad003ef8d24", + "zh:4269f01a98513651ad66763c16b268f4c2da76cc892ccfd54b401fff6cc11667", + "zh:51904350b9c728f963eef0c28f1d43e73d010333133eb7f30999a8fb6a0cc3d8", + "zh:73a66611359b83d0c3fcba2984610273f7954002febb8a57242bbb86d967b635", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:7ae387993a92bcc379063229b3cce8af7eaf082dd9306598fcd42352994d2de0", + "zh:9e0f365f807b088646db6e4a8d4b188129d9ebdbcf2568c8ab33bddd1b82c867", + "zh:b5263acbd8ae51c9cbffa79743fbcadcb7908057c87eb22fd9048268056efbc4", + "zh:dfcd88ac5f13c0d04e24be00b686d069b4879cc4add1b7b1a8ae545783d97520", + ] +} + +provider "registry.terraform.io/hashicorp/null" { + version = "3.2.2" + constraints = ">= 2.0.0" + hashes = [ + "h1:IMVAUHKoydFrlPrl9OzasDnw/8ntZFerCC9iXw1rXQY=", + "zh:3248aae6a2198f3ec8394218d05bd5e42be59f43a3a7c0b71c66ec0df08b69e7", + "zh:32b1aaa1c3013d33c245493f4a65465eab9436b454d250102729321a44c8ab9a", + "zh:38eff7e470acb48f66380a73a5c7cdd76cc9b9c9ba9a7249c7991488abe22fe3", + "zh:4c2f1faee67af104f5f9e711c4574ff4d298afaa8a420680b0cb55d7bbc65606", + "zh:544b33b757c0b954dbb87db83a5ad921edd61f02f1dc86c6186a5ea86465b546", + "zh:696cf785090e1e8cf1587499516b0494f47413b43cb99877ad97f5d0de3dc539", + "zh:6e301f34757b5d265ae44467d95306d61bef5e41930be1365f5a8dcf80f59452", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:913a929070c819e59e94bb37a2a253c228f83921136ff4a7aa1a178c7cce5422", + "zh:aa9015926cd152425dbf86d1abdbc74bfe0e1ba3d26b3db35051d7b9ca9f72ae", + "zh:bb04798b016e1e1d49bcc76d62c53b56c88c63d6f2dfe38821afef17c416a0e1", + "zh:c23084e1b23577de22603cff752e59128d83cfecc2e6819edadd8cf7a10af11e", + ] +} diff --git a/aws-lambda-tutorial/components/lambda-function/main.tf b/aws-lambda-tutorial/components/lambda-function/main.tf new file mode 100644 index 0000000..2bb9b07 --- /dev/null +++ b/aws-lambda-tutorial/components/lambda-function/main.tf @@ -0,0 +1,24 @@ +module "lambda_function" { + source = "terraform-aws-modules/lambda/aws" + + function_name = var.function_name + image_uri = var.image_uri + package_type = "Image" + create_package = false + + attach_policy_json = true + policy_json = <