diff --git a/Makefile b/Makefile index e7ccdf3..872621c 100644 --- a/Makefile +++ b/Makefile @@ -35,17 +35,6 @@ GO_FILES := $(shell \ -o -name '*.go' -print | cut -b3-) MODULE_DIRS = . -terraform-deploy: - terraform init - terraform plan - terraform apply -auto-approve - -terraform-destroy: - terraform destroy -auto-approve - rm -rf .terraform - rm -rf terraform.tfstate* - rm -rf .terraform.lock.hcl - .PHONY: lint lint: $(STATICCHECK) diff --git a/go.mod b/go.mod index b3bf5cc..c4f5aa5 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/aws/aws-sdk-go-v2/config v1.26.1 github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.12 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.26.6 + github.com/go-redis/redis/v8 v8.11.5 github.com/stretchr/testify v1.7.2 ) @@ -26,7 +27,9 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 // indirect github.com/aws/smithy-go v1.19.0 // indirect + github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index fbac5d5..4e2cb6f 100644 --- a/go.sum +++ b/go.sum @@ -36,9 +36,15 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.26.5 h1:5UYvv8JUvllZsRnfrcMQ+hJ9jNIC github.com/aws/aws-sdk-go-v2/service/sts v1.26.5/go.mod h1:XX5gh4CB7wAs4KhcF46G6C8a2i7eupU19dcAAE+EydU= github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM= github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= +github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= +github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= diff --git a/main.tf b/main.tf deleted file mode 100644 index 59736fc..0000000 --- a/main.tf +++ /dev/null @@ -1,134 +0,0 @@ -provider "aws" { - region = "eu-central-1" -} - -resource "aws_dynamodb_table" "table" { - name = "ShortLinkDB" - billing_mode = "PAY_PER_REQUEST" - hash_key = "id" - - attribute { - name = "id" - type = "S" - } -} - -resource "aws_lambda_function" "generate_link" { - function_name = "GenerateLinkFunction" - handler = "bootstrap" - runtime = "provided.al2" - memory_size = 128 - timeout = 5 - - environment { - variables = { - TABLE = aws_dynamodb_table.table.name - } - } - - tracing_config { - mode = "Active" - } - - filename = "functions/generate_link/deployment-package.zip" - source_code_hash = filebase64sha256("functions/generate_link/deployment-package.zip") - - role = aws_iam_role.lambda_exec.arn -} - -resource "aws_iam_role" "lambda_exec" { - name = "lambda_exec_role" - - assume_role_policy = jsonencode({ - Version = "2012-10-17", - Statement = [ - { - Action = "sts:AssumeRole", - Effect = "Allow", - Principal = { - Service = "lambda.amazonaws.com" - }, - }, - ], - }) -} - -resource "aws_iam_policy_attachment" "lambda_basic_execution" { - name = "lambda_basic_execution" - roles = [aws_iam_role.lambda_exec.name] - policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" -} - - -resource "aws_iam_policy" "lambda_policy" { - name = "lambda_policy" - path = "/" - description = "IAM policy for Lambda to access DynamoDB" - - policy = jsonencode({ - Version = "2012-10-17", - Statement = [ - { - Effect = "Allow", - Action = "dynamodb:PutItem", - Resource = aws_dynamodb_table.table.arn, - }, - ], - }) -} - -resource "aws_iam_role_policy_attachment" "lambda_policy_attach" { - role = aws_iam_role.lambda_exec.name - policy_arn = aws_iam_policy.lambda_policy.arn -} - -resource "aws_apigatewayv2_api" "http_api" { - name = "MyHttpApi" - protocol_type = "HTTP" -} - -resource "aws_apigatewayv2_deployment" "http_api_deployment" { - api_id = aws_apigatewayv2_api.http_api.id - - depends_on = [ - aws_apigatewayv2_route.http_api_route, - ] - - lifecycle { - create_before_destroy = true - } -} - -resource "aws_apigatewayv2_stage" "http_api_stage" { - api_id = aws_apigatewayv2_api.http_api.id - name = "$default" - deployment_id = aws_apigatewayv2_deployment.http_api_deployment.id -} - -resource "aws_apigatewayv2_integration" "http_api_integration" { - api_id = aws_apigatewayv2_api.http_api.id - integration_type = "AWS_PROXY" - integration_uri = aws_lambda_function.generate_link.invoke_arn - payload_format_version = "2.0" -} - - -resource "aws_apigatewayv2_route" "http_api_route" { - api_id = aws_apigatewayv2_api.http_api.id - route_key = "PUT /links" - target = "integrations/${aws_apigatewayv2_integration.http_api_integration.id}" -} - -resource "aws_lambda_permission" "api_gateway_lambda" { - statement_id = "AllowExecutionFromAPIGateway" - action = "lambda:InvokeFunction" - function_name = aws_lambda_function.generate_link.function_name - principal = "apigateway.amazonaws.com" - source_arn = "${aws_apigatewayv2_api.http_api.execution_arn}/*/*" - depends_on = [aws_apigatewayv2_deployment.http_api_deployment] -} - -output "api_url" { - description = "API Gateway endpoint URL for the GenerateLink function" - value = "${aws_apigatewayv2_api.http_api.api_endpoint}/links" -} \ No newline at end of file