CircleCI-Public / aws-ecs-orb

An orb that simplifies deployment to Amazon's Elastic Container Service (ECS). Supports both EC2 and Fargate launch types.
https://circleci.com/orbs/registry/orb/circleci/aws-ecs
MIT License
51 stars 80 forks source link

`region` parameter not correctly override ${AWS_DEFAULT_REGION} env #220

Open DeliciousKokas opened 5 days ago

DeliciousKokas commented 5 days ago

Orb version:

5.x

What happened:

During the running deploy_service_update job, it's generate error Invalid endpoint: https://ecs..amazonaws.com It's seems to error related missing region parameter, but it's correctly setup already.

However, it's resolved when setting ${AWS_DEFAULT_REGION} which should be an optional. Seems to during the steps, it directly refer to ${AWS_DEFAULT_REGION} env not parameter.

Expected behavior:

Make it region parameter override ${AWS_DEFAULT_REGION} env, and correct command refer to parameter.

Additional Information:

Taking look deploy_service_update job on orb source 5.x, below steps were included. And it's not using registered parameter but only take it directly from ${AWS_DEFAULT_REGION}.

### 5.x
- when:
    condition: << parameters.skip_task_definition_registration >>
    steps:
        - run:
            command: |
                TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \
                  --task-definition << parameters.family >> \
                  --output text \
                  --query 'taskDefinition.taskDefinitionArn' \
                  --profile << parameters.profile_name >> \
                  --region ${AWS_DEFAULT_REGION})
                echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV
            name: Retrieve previous task definition

Same steps on version 4.1, there was no region flag. So I assuming it's only effected on 5.x.

### 4.1
- when:
    condition: << parameters.skip_task_definition_registration >>
    steps:
        - run:
            command: |
                TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \
                  --task-definition << parameters.family >> \
                  --output text \
                  --query 'taskDefinition.taskDefinitionArn' \
                  --profile=<< parameters.profile_name >>)
                echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV
            name: Retrieve previous task definition
marboledacci commented 4 days ago

I think this was partially fixed with #219. I'm creating #221 so this fix is applied to the job as well.

marboledacci commented 4 days ago

I think this new version should solve your problem 5.2.1

DeliciousKokas commented 4 days ago

Thanks for the quick respond, seems to be able to point out region from parameters.

+@ I also found similar parameters on verify_revision_is_deployed command. Although, this command does not includes description about region parameters, but wondering was it on purpose.

 DEPLOYMENTS=$(aws ecs describe-services \
      --profile "${ORB_STR_PROFILE_NAME}" \
      --cluster "$ORB_STR_CLUSTER_NAME" \
      --services "${ORB_STR_SERVICE_NAME}" \
      --region "${AWS_DEFAULT_REGION}" \
      --output text \
      --query 'services[0].deployments[].[taskDefinition, status]' \
      "$@")
  NUM_DEPLOYMENTS=$(aws ecs describe-services \
      --profile "${ORB_STR_PROFILE_NAME}" \
      --cluster "$ORB_STR_CLUSTER_NAME" \
      --services "${ORB_STR_SERVICE_NAME}" \
      --region "${AWS_DEFAULT_REGION}" \
      --output text \
      --query 'length(services[0].deployments)' \
      "$@")
  TARGET_REVISION=$(aws ecs describe-services \
      --profile "${ORB_STR_PROFILE_NAME}" \
      --cluster "$ORB_STR_CLUSTER_NAME" \
      --services "${ORB_STR_SERVICE_NAME}" \
      --region "${AWS_DEFAULT_REGION}" \
      --output text \
      --query "services[0].deployments[?taskDefinition==\`$ORB_STR_TASK_DEF_ARN\` && runningCount == desiredCount && (status == \`PRIMARY\` || status == \`ACTIVE\`)][taskDefinition]" \
      "$@")
marboledacci commented 3 days ago

The initial design of the orb was to use the environment variables for the region. For the update_service command there was a recent addition of the parameter to solve some specific situation and that's why it't the only having it.

nanophate commented 3 hours ago

Hi @marboledacci

Thanks for working on this issue ✨

Support are receiving request from user that it would be beneficial to be able to pass on pipeline parameters like the other command. Will the team able to also apply it for update_task_definition command which is calling src/scripts/get_prev_task.sh as well?

PREVIOUS_TASK_DEFINITION="$(aws ecs describe-task-definition \
    --task-definition "${ECS_TASK_DEFINITION_NAME}" \
    --include TAGS --profile "${ORB_STR_PROFILE_NAME}" \
    --region "${AWS_DEFAULT_REGION}" "$@")"

https://github.com/CircleCI-Public/aws-ecs-orb/blob/master/src/scripts/get_prev_task.sh#L20C173-L20C191