Skip to content

Commit 8e07fee

Browse files
whummerclaude
andcommitted
Explicitly set AWS credentials and endpoint URL in ECS task definition
LocalStack may not reliably inject AWS_ENDPOINT_URL into ECS task containers in all environments. Setting it explicitly to localhost.localstack.cloud:4566 ensures the fulfillment container always reaches LocalStack regardless of runtime injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7899d3a commit 8e07fee

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

01-serverless-app/services/fulfillment/fulfill.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
TABLE_NAME = os.environ["ORDERS_TABLE"]
1010
RECEIPTS_BUCKET = os.environ["RECEIPTS_BUCKET"]
1111

12-
# LocalStack injects AWS_ENDPOINT_URL automatically into ECS task containers.
12+
endpoint = os.environ.get("AWS_ENDPOINT_URL", "")
13+
print(f"Connecting to endpoint: {endpoint or '(default AWS)'}", flush=True)
14+
1315
dynamodb = boto3.resource("dynamodb")
1416
s3 = boto3.client("s3")
1517

01-serverless-app/terraform/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ resource "aws_ecs_task_definition" "fulfillment" {
140140
name = "fulfillment"
141141
image = "${aws_ecr_repository.fulfillment.repository_url}:latest"
142142
environment = [
143-
{ name = "ORDERS_TABLE", value = aws_dynamodb_table.orders.name },
144-
{ name = "RECEIPTS_BUCKET", value = aws_s3_bucket.receipts.bucket },
143+
{ name = "ORDERS_TABLE", value = aws_dynamodb_table.orders.name },
144+
{ name = "RECEIPTS_BUCKET", value = aws_s3_bucket.receipts.bucket },
145+
{ name = "AWS_ENDPOINT_URL", value = "http://localhost.localstack.cloud:4566" },
146+
{ name = "AWS_DEFAULT_REGION", value = "us-east-1" },
147+
{ name = "AWS_ACCESS_KEY_ID", value = "test" },
148+
{ name = "AWS_SECRET_ACCESS_KEY", value = "test" },
145149
]
146150
}])
147151
}

0 commit comments

Comments
 (0)