Skip to content

Commit 9ad8eb8

Browse files
author
claudfuen
committed
fix: correct aws ecs run-task syntax in deploy scripts
- Fix incorrect --subnets and --security-groups parameters - Use proper --network-configuration with JSON structure - Add --launch-type FARGATE parameter - Add ECR image processing delay before deployment - Apply fixes to both deploy.sh and GitHub Actions workflow
1 parent e4a4d00 commit 9ad8eb8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

.github/workflows/deploy.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ jobs:
7878
7979
- name: Run database migrations
8080
run: |
81+
# Get subnet and security group for migration task
82+
PRIVATE_SUBNET=$(aws ec2 describe-subnets --filters "Name=tag:Type,Values=private" --query 'Subnets[0].SubnetId' --output text)
83+
CODEBUILD_SG=$(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=pathfinder-codebuild-sg" --query 'SecurityGroups[0].GroupId' --output text)
84+
85+
echo "Using subnet: $PRIVATE_SUBNET"
86+
echo "Using security group: $CODEBUILD_SG"
87+
8188
TASK_ARN=$(aws ecs run-task \
8289
--cluster pathfinder \
8390
--task-definition pathfinder-migration:latest \
84-
--subnets $(aws ec2 describe-subnets --filters "Name=tag:Type,Values=private" --query 'Subnets[0].SubnetId' --output text) \
85-
--security-groups $(aws ec2 describe-security-groups --filters "Name=tag:Name,Values=pathfinder-codebuild-sg" --query 'SecurityGroups[0].GroupId' --output text) \
91+
--launch-type FARGATE \
92+
--network-configuration "awsvpcConfiguration={subnets=[$PRIVATE_SUBNET],securityGroups=[$CODEBUILD_SG],assignPublicIp=ENABLED}" \
8693
--query 'tasks[0].taskArn' --output text)
8794
8895
echo "Migration task started: $TASK_ARN"
@@ -122,6 +129,10 @@ jobs:
122129
123130
- name: Deploy application
124131
run: |
132+
# Wait for ECR to process the new image
133+
echo "Waiting for ECR to process new image..."
134+
sleep 30
135+
125136
# Update ECS service to use new image
126137
aws ecs update-service \
127138
--cluster pathfinder \

scripts/deploy.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ codebuild_sg=$(aws ec2 describe-security-groups \
7979
--filters "Name=tag:Name,Values=pathfinder-codebuild-sg" \
8080
--query 'SecurityGroups[0].GroupId' --output text)
8181

82-
# Run migration task
82+
echo "Using subnet: $private_subnet"
83+
echo "Using security group: $codebuild_sg"
84+
85+
# Run migration task with correct syntax
8386
migration_task_arn=$(aws ecs run-task \
8487
--cluster "$CLUSTER_NAME" \
8588
--task-definition pathfinder-migration:latest \
86-
--subnets "$private_subnet" \
87-
--security-groups "$codebuild_sg" \
89+
--launch-type FARGATE \
90+
--network-configuration "awsvpcConfiguration={subnets=[$private_subnet],securityGroups=[$codebuild_sg],assignPublicIp=ENABLED}" \
8891
--query 'tasks[0].taskArn' --output text)
8992

9093
echo "Migration task ARN: $migration_task_arn"
@@ -117,6 +120,10 @@ wait_for_build "$app_build_id" "Application"
117120
# Step 5: Deploy Application
118121
echo -e "${YELLOW}🚢 Step 5: Deploying application...${NC}"
119122

123+
# Wait for ECR to process the new image
124+
echo -e "${YELLOW}⏳ Waiting for ECR to process new image...${NC}"
125+
sleep 30
126+
120127
# Update ECS service
121128
aws ecs update-service \
122129
--cluster "$CLUSTER_NAME" \

0 commit comments

Comments
 (0)