Last active
September 25, 2025 19:45
-
-
Save KyMidd/d2dfa09bfc0d1c3b89055d98a8e87183 to your computer and use it in GitHub Desktop.
Terraform configuration for ECR repository, Docker build/push, and containerized Lambda function deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ECR Repository for container images | |
| resource "aws_ecr_repository" "worker_container" { | |
| name = "${var.bot_name}-worker" | |
| image_tag_mutability = "MUTABLE" | |
| image_scanning_configuration { | |
| scan_on_push = true | |
| } | |
| lifecycle_policy {} | |
| } | |
| # Build and push Docker image using null_resource | |
| resource "null_resource" "docker_build_push" { | |
| triggers = { | |
| # Rebuild when any source file changes | |
| source_hash = data.archive_file.lambda_source.output_md5 | |
| } | |
| provisioner "local-exec" { | |
| command = <<-EOF | |
| # Login to ECR | |
| aws ecr get-login-password --region ${data.aws_region.current.name} | docker login --username AWS --password-stdin ${aws_ecr_repository.worker_container.repository_url} | |
| # Build image for ARM64 | |
| docker build --platform linux/arm64 -t ${aws_ecr_repository.worker_container.repository_url}:latest . | |
| # Push image | |
| docker push ${aws_ecr_repository.worker_container.repository_url}:latest | |
| EOF | |
| working_dir = "${path.module}" | |
| } | |
| depends_on = [aws_ecr_repository.worker_container] | |
| } | |
| # Worker Lambda function using container image | |
| resource "aws_lambda_function" "worker" { | |
| function_name = "${var.bot_name}-Worker" | |
| role = aws_iam_role.lambda_execution_role.arn | |
| # Container configuration | |
| package_type = "Image" | |
| image_uri = "${aws_ecr_repository.worker_container.repository_url}:latest" | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment