0

I have a specific script that host some important configurations. The script basically generates a record structure on my documentDB.

This particular script is hosted on an independent repository on Github. I want to create a task when the code is merged into master using github action. This task should call the script that's defined on the Dockerfile.

My current github action looks like this

on:
  pull_request:
    branches:
      - master

name: Deploy to Amazon ECS

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    env:
      ENVIRONMENT: ${{ github.head_ref == 'master' && 'prod' || github.ref_name == 'master' && 'prod' || github.head_ref || github.ref_name }}

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AVERO_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AVERO_AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.AVERO_AWS_DEFAULT_REGION }}

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v1

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPOSITORY: module
          IMAGE_TAG: ${{ github.sha }}
          ENVIRONMENT: ${{ secrets.ENVIRONMENT || 'test' }}
        run: |
          docker build --build-arg --build-arg ENVIRONMENT="${ENVIRONMENT}" -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
          docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
          echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

      - name: Replace task-definition variables with data from the env
        uses: microsoft/variable-substitution@v1
        with:
          files: .aws/task-definition.json
        env:
          containerDefinitions.0.name: ${{ env.ENVIRONMENT }}-container
          containerDefinitions.0.environment.0.value: ${{ env.ENVIRONMENT == 'prod' && 'production' || env.ENVIRONMENT }}
          containerDefinitions.0.secrets.0.valueFrom: /system/${{ env.ENVIRONMENT }}/some-value
          containerDefinitions.0.secrets.1.valueFrom: /system/${{ env.ENVIRONMENT }}/some-value
          containerDefinitions.0.logConfiguration.options.awslogs-group: /system/${{ env.ENVIRONMENT }}/module
          containerDefinitions.0.logConfiguration.options.awslogs-region: ${{ secrets.AVERO_AWS_DEFAULT_REGION }}
          family: ${{ env.ENVIRONMENT }}-task-definition
          taskRoleArn: arn:aws:iam::${{secrets.AVERO_AWS_ACCOUNT_NUMBER}}:role/system/${{ env.ENVIRONMENT }}/module/${{ env.ENVIRONMENT }}-system-role
          executionRoleArn: arn:aws:iam::${{secrets.AVERO_AWS_ACCOUNT_NUMBER}}:role/system/${{ env.ENVIRONMENT }}/module/${{ env.ENVIRONMENT }}-system-role

      - name: Fill in the new image ID in the Amazon ECS task definition
        id: task-def
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          task-definition: .aws/task-definition.json
          container-name: ${{ env.ENVIRONMENT }}-container
          image: ${{ steps.build-image.outputs.image }}

      - name: Run my ECS task
        uses: zamarawka/aws-run-fargate-task@v1
        with:
          task_name: ${{ env.ENVIRONMENT }}-task-definition
          cluster: ${{ env.ENVIRONMENT }}-cluster
          wait: true

When running the workflow, I have an exception on the last step. The error looks like follows: Run fargate task Fetch network settings InvalidParameterValue: The filter 'null' is invalid

Some considerations:

  • I do not want to create a fargate service, because I do not have any need to keep this script running after it finishes.
  • I cannot use Lambda because the process could take +15min

I realized that when running a task from the web interface the network configuration is required, that's something I didn't really send on the task-definition because there is no parameter for that.

Do you have any idea how can I achieve this?

Mark B
  • 183,023
  • 24
  • 297
  • 295
fingerprints
  • 2,751
  • 1
  • 25
  • 45

1 Answers1

0

You say there's no parameter for network configuration, but when I look at that GitHub action I see parameters for all the network settings like subnet_ids and public_ip: https://github.com/zamarawka/aws-run-fargate-task

At a minimum you probably need to set those two settings, and probably the security group as well.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • thanks @Mark B. I didn't realize that those parameters where available. So, I'm here trying again. My problem now is that I do not know how to provide those parameters in a list. `- name: Run task uses: zamarawka/aws-run-fargate-task@v1 with: task_name: ${{ env.ENVIRONMENT }}-config-task-definition cluster: ${{ env.ENVIRONMENT }}-cluster wait: true subnet_ids: subnet-1 subnet-2 subnet-3 public_ip: true sg_names: ${{ env.ENVIRONMENT }}-module-sg` Do you? – fingerprints Aug 31 '22 at 14:27
  • Your GitHub actions configuration file is a standard YAML file. So you would use standard YAML list syntax: https://www.w3schools.io/file/yaml-arrays/ – Mark B Aug 31 '22 at 14:48
  • It didn't really work out for me. Even with the yaml list syntax - name: Run my ECS task uses: zamarawka/aws-run-fargate-task@v1 with: task_name: task-definition-name cluster: cluster-name wait: true public_ip: false subnet_ids: [subnet-1, subnet-2, subnet-3] sg_names: [ sg-name ] I'm now having an error pointing to the `subnet_ids` line saying that a sequence was not expected. – fingerprints Aug 31 '22 at 15:27
  • 1
    Since you are running a single task, and not a load-balanced service, why not just specify a single value? If you want more clarifications on what this GitHub action expects, you should reach out to the author on GitHub since it is a non-official action. – Mark B Aug 31 '22 at 15:31