1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # /list
- # Returns the event, and the context
- data "archive_file" "lambda_list" {
- type = "zip"
- source_file = "${path.module}/scripts/list.py"
- output_path = "${path.module}/tmp/list.zip"
- }
- resource "aws_lambda_function" "lambda_list" {
- # If the file is not in the current working directory you will need to include a
- # path.module in the filename.
- filename = data.archive_file.lambda_list.output_path
- function_name = "game_server_list"
- role = aws_iam_role.lambda_role.arn
- handler = "list.lambda_handler"
- # The filebase64sha256() function is available in Terraform 0.11.12 and later
- # For Terraform 0.11.11 and earlier, use the base64sha256() function and the file() function:
- # source_code_hash = "${base64sha256(file("lambda_function_payload.zip"))}"
- source_code_hash = data.archive_file.lambda_list.output_base64sha256
- runtime = "python3.9"
- environment {
- variables = {
- foo = "bar"
- }
- }
- vpc_config {
- subnet_ids = module.vpc.public_subnets # using public for now, to allow for Internets
- security_group_ids = [aws_security_group.allow_all.id]
- }
- tags = local.tags
- }
- resource "aws_lambda_permission" "api_lambda_list" {
- statement_id = "AllowExecutionFromAPI"
- action = "lambda:InvokeFunction"
- function_name = aws_lambda_function.lambda_list.function_name
- principal = "apigateway.amazonaws.com"
- # The /*/*/* part allows invocation from any stage, method and resource path
- # within API Gateway REST API.
- #source_arn = "${aws_apigatewayv2_stage.test.execution_arn}/*/*/*"
- source_arn = "${aws_apigatewayv2_api.gateway.execution_arn}/*/*/*"
- #qualifier = aws_lambda_alias.test_alias.name
- }
- # The API Gateway Route
- resource "aws_apigatewayv2_integration" "lambda_list" {
- api_id = aws_apigatewayv2_api.gateway.id
- integration_type = "AWS_PROXY"
- connection_type = "INTERNET"
- integration_method = "POST"
- integration_uri = "arn:aws:apigateway:${data.aws_region.current.name}:lambda:path/2015-03-31/functions/arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.id}:function:${aws_lambda_function.lambda_list.function_name}/invocations"
- }
- resource "aws_apigatewayv2_route" "lambda_list_GET" {
- api_id = aws_apigatewayv2_api.gateway.id
- route_key = "GET /list"
- target = "integrations/${aws_apigatewayv2_integration.lambda_list.id}"
- authorization_type = "JWT"
- authorizer_id = aws_apigatewayv2_authorizer.auth.id
- }
- resource "aws_apigatewayv2_route" "lambda_list_POST" {
- api_id = aws_apigatewayv2_api.gateway.id
- route_key = "POST /list"
- target = "integrations/${aws_apigatewayv2_integration.lambda_list.id}"
- authorization_type = "JWT"
- authorizer_id = aws_apigatewayv2_authorizer.auth.id
- }
|