ECS Task Fails to Connect to Database When Triggered from GitHub Actions in Staging Environment

  Kiến thức lập trình

I have an ECS Task that I am attempting to run from my GitHub Actions workflow. This setup works perfectly in my Development environment. However, in my Staging environment, the task fails with an Npgsql.NpgsqlException (0x80004005): Failed to connect… exception.

The task starts correctly but times out when attempting to connect to the database. Strangely, this issue only occurs when the task is started by my GitHub Actions workflow. When I run the task manually from the AWS Console using the same details, it works perfectly. I have compared the tasks created by both methods and they are identical in every visible way.

I have tried granting all IAM permissions and opening all ports for testing, but it makes no difference to the outcome.

Here is a snippet from my GitHub Actions workflow:

      - name: Run My Task
        run: |
          aws ecs run-task --cluster ${{ env.ECS_CLUSTER }} --task-definition MyTaskDefinition --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets = [ ${{ env.SUBNET_A }},${{ env.SUBNET_B }} ], securityGroups=[${{ env.SECURITY_GROUP }}],assignPublicIp=ENABLED}"

I can confirm the following:

  • All environment variables used are correct and match those used in the console.
  • I am running the task using the same security group and subnets in both cases.
  • I am using the same IAM roles for the task and task execution.
  • I am using the exact same task definition.

Despite these confirmations, the task still fails when triggered from GitHub Actions. Any insights or suggestions on what might be causing this issue would be greatly appreciated.

Additional Context:

  • The database is a PostgreSQL instance.
  • This issue does not occur in the Development environment; it is specific to the Staging environment.
  • There are no known significant differences between the Development and Staging environments.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT