Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Read arn region#844

Merged
SoManyHs merged 3 commits intoaws:ecs-localfrom
SoManyHs:read-arn-region
Jul 2, 2019
Merged

Read arn region#844
SoManyHs merged 3 commits intoaws:ecs-localfrom
SoManyHs:read-arn-region

Conversation

@SoManyHs
Copy link
Copy Markdown
Contributor

@SoManyHs SoManyHs commented Jul 2, 2019

Previously, passing a full task definition ARN to local up would not account for the region specified in the ARN and would default to the region configuration of the ECS client. This change enables local up to fetch and run a task definition from the correct region specified in its ARN.

Fixes #821


Enter [N/A] in the box, if an item is not applicable to your change.

Testing

  • Unit tests passed
  • Integration tests passed
  • Unit tests added for new functionality
  • Listed manual checks and their outputs in the comments (example)
  • Link to issue or PR for the integration tests:

Documentation

  • Contacted our doc writer
  • Updated our README

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@SoManyHs SoManyHs requested review from efekarakus and kohidave July 2, 2019 14:42
@SoManyHs
Copy link
Copy Markdown
Contributor Author

SoManyHs commented Jul 2, 2019

ECS config (default region set to eu-west-2)

~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ cat ~/.ecs/config
version: v1
default: default
clusters:
  default:
    cluster: default
    region: eu-west-2
    default_launch_type: ""

Listing available task definitions in default region and diferent region (us-west-2):

~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ aws ecs list-task-definitions --region eu-west-2
{
    "taskDefinitionArns": [
        "arn:aws:ecs:eu-west-2:xxxxxxxxxx151:task-definition/foo:1",
        "arn:aws:ecs:eu-west-2:xxxxxxxxxx151:task-definition/test_fields:1"
}


~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ aws ecs list-task-definitions --region us-west-2
{
    "taskDefinitionArns": [
	"arn:aws:ecs:us-west-2:xxxxxxxxxx151:task-definition/hhhSleep300:1",
        "arn:aws:ecs:us-west-2:xxxxxxxxxx151:task-definition/test_fields:71"
}

Local up with task def name from different region than configured region:

~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ ecs-cli local up -t hhhSleep300
FATA[0000] Error with local create: ClientException: Unable to describe task definition.
	status code: 400, request id: 7f55b5a5-9c9e-11e9-bcf5-1592f9630544

With task def name that exists in region configured:

~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ ecs-cli local up -t test_fields
INFO[0000] PID mode can only be set to 'host' when running tasks locally.  pid=
INFO[0000] IPC mode can only be set to 'host' or 'none' when running tasks locally.  ipc=
Successfully wrote docker-compose.local.yml
INFO[0000] The network ecs-local-network already exists
INFO[0000] The amazon-ecs-local-container-endpoints container already exists with ID 7ababd8696c13e27740cf2279425bb938770d577c5256f3fd8d73255e906201a
INFO[0000] Started container with ID 7ababd8696c13e27740cf2279425bb938770d577c5256f3fd8d73255e906201a
Compose out: amazon-ecs-cli_web_1 is up-to-date

With ARN of task definition in different region than configured region

~/go/src/github.com/aws/amazon-ecs-cli(read-arn-region)$ ecs-cli local up -t arn:aws:ecs:us-west-2:xxxxxxxxxx151:task-definition/hhhSleep300:188
INFO[0000] PID mode can only be set to 'host' when running tasks locally.  pid=
INFO[0000] IPC mode can only be set to 'host' or 'none' when running tasks locally.  ipc=
docker-compose.local.yml file already exists. Do you want to write over this file? [y/N]
y
Successfully wrote docker-compose.local.yml
INFO[0002] The network ecs-local-network already exists
INFO[0003] The amazon-ecs-local-container-endpoints container already exists with ID 7ababd8696c13e27740cf2279425bb938770d577c5256f3fd8d73255e906201a
INFO[0003] Started container with ID 7ababd8696c13e27740cf2279425bb938770d577c5256f3fd8d73255e906201a
Compose out: Found orphan containers (amazon-ecs-cli_web_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Starting amazon-ecs-cli_hhhSleep300Test_1 ... done

@SoManyHs
Copy link
Copy Markdown
Contributor Author

SoManyHs commented Jul 2, 2019

Not quite sure how best to unit test this, since the relevant changes would involve calling a mock client.

Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just two small questions

}

commandConfig, err := newCommandConfig(p.context, rdwr)
commandConfig, err := newCommandConfig(p.context, rdwr, "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of getSecret() right? I don't think this function is used anymore 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes -- also looking at your changes from #808 we can probably get rid of the GetSecretValue method in client method -- I'll remove them in a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sounds good

ecsConfig.Cluster = clusterFromEnv
// Determine Cloudformation StackName
if ecsConfig.Version == iniConfigVersion {
ecsConfig.CFNStackName = ecsConfig.CFNStackNamePrefix + ecsConfig.Cluster
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we add this? I don't think this check was there before right

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for backwards compatibility for the configure workflows that used the old config file format. /c @PettitWesley

@SoManyHs SoManyHs merged commit 195753b into aws:ecs-local Jul 2, 2019
@SoManyHs SoManyHs deleted the read-arn-region branch July 2, 2019 18:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants