Skip to content

Commit

Permalink
building docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
arnol377 committed Apr 16, 2025
1 parent 018399a commit b07b24f
Show file tree
Hide file tree
Showing 17 changed files with 1,476 additions and 288 deletions.
25 changes: 25 additions & 0 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions .terraform_commits
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T13:12:39.190090"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T13:13:33.377155"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T13:14:04.341717"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T13:46:26.319927"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T14:39:49.477391"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T14:41:30.994495"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T16:03:19.141297"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T16:06:13.577362"
},
{
"commit_hash": "018399a6523b3c5c1d7503b2c0de8cd66eb8d8e5",
"commit_message": "Merge branch 'main' of github.e.it.census.gov:SCT-Engineering/eks-automation-lambda",
"author": "arnol377",
"timestamp": "2025-04-16T16:07:17.588493"
}
]
31 changes: 21 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.PHONY: init venv install-deps clean terraform-init terraform-plan terraform-apply package all
.PHONY: init venv install-deps clean init plan apply destroy all invoke-lambda package-lambda

PYTHON=python3
PIP=pip3
TERRAFORM=terraform
TERRAFORM=tf
VENV=.venv
VENV_BIN=$(VENV)/bin
VENV_PIP=$(VENV_BIN)/pip

# Set PIP_CONFIG_FILE to use custom pip.conf
export PIP_CONFIG_FILE=$(CURDIR)/scripts/pip.conf

all: venv install-deps package terraform-apply
all: venv install-deps apply

venv:
test -d $(VENV) || $(PYTHON) -m venv $(VENV)
Expand All @@ -26,17 +26,28 @@ clean:
rm -rf .terraform/
rm -rf $(VENV)

package: venv
source $(VENV_BIN)/activate && chmod +x scripts/package.sh && ./scripts/package.sh

terraform-init:
init:
$(TERRAFORM) init

terraform-plan: terraform-init
plan: init
$(TERRAFORM) plan

terraform-apply: terraform-init package
apply: init
$(TERRAFORM) apply -auto-approve

terraform-destroy:
destroy: init
$(TERRAFORM) destroy -auto-approve

invoke-lambda:
@echo "Invoking Lambda function via API Gateway..."
@source $(VENV_BIN)/activate && $(PYTHON) scripts/invoke_lambda.py $(ARGS)
@echo "For more options, run: make invoke-lambda ARGS='-h'"

package-lambda: venv install-deps
@echo "Packaging Lambda function and dependencies..."
@mkdir -p dist
@source $(VENV_BIN)/activate && $(PYTHON) scripts/package_lambda.py $(CURDIR)
@echo "Tainting S3 objects to ensure they are recreated on next apply..."
-$(TERRAFORM) taint 'aws_s3_object.lambda_package'
-$(TERRAFORM) taint 'aws_s3_object.lambda_layer'
@echo "Lambda package created successfully in the dist/ directory"
63 changes: 63 additions & 0 deletions api_gateway.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# API Gateway HTTP API without CORS (we'll add CORS separately)
resource "aws_apigatewayv2_api" "lambda_api" {
name = "${var.name}-api-gateway"
protocol_type = "HTTP"
cors_configuration {
allow_credentials = false
allow_headers = [
"*",
]
allow_methods = [
"POST",
]
allow_origins = [
"*",
]
expose_headers = [
"*",
]
max_age = 86400
}
lifecycle {
ignore_changes = [
cors_configuration
]
}
}

# API Gateway Integration with Lambda
resource "aws_apigatewayv2_integration" "lambda_integration" {
api_id = aws_apigatewayv2_api.lambda_api.id
integration_type = "AWS_PROXY"
integration_uri = aws_lambda_function.eks_automation.invoke_arn
payload_format_version = "2.0"
}

# API Gateway Route for POST requests
resource "aws_apigatewayv2_route" "lambda_route" {
api_id = aws_apigatewayv2_api.lambda_api.id
route_key = "POST /"
target = "integrations/${aws_apigatewayv2_integration.lambda_integration.id}"
}

# API Gateway Stage
resource "aws_apigatewayv2_stage" "lambda_stage" {
api_id = aws_apigatewayv2_api.lambda_api.id
name = "$default"
auto_deploy = true
}

# Lambda Permission for API Gateway
resource "aws_lambda_permission" "api_gateway_permission" {
statement_id = "AllowAPIGatewayInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.eks_automation.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_apigatewayv2_api.lambda_api.execution_arn}/*/*"
}

# Add API Gateway URL to outputs
output "api_gateway_invoke_url" {
value = "${aws_apigatewayv2_stage.lambda_stage.invoke_url}"
description = "API Gateway URL for invoking the Lambda function"
}
File renamed without changes.
5 changes: 5 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data aws_partition current {}

data "aws_caller_identity" "current" {}

data aws_region current {}
Loading

0 comments on commit b07b24f

Please sign in to comment.