Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): best-effort create service linked role for ECS on env init #1749

Merged
merged 3 commits into from
Dec 11, 2020

Conversation

efekarakus
Copy link
Contributor

For accounts that never used ECS before, the service linked role does not exist which results in ECS not being able to create the cluster during env init.

This change attempts a best-effort creation of the role before creating the environment stack.

Resolves #1324

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@efekarakus efekarakus requested a review from a team as a code owner December 10, 2020 22:29
Copy link
Contributor

@bvtujo bvtujo 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, just a couple of questions

// 1. Attempt to create the service linked role if it doesn't exist.
// If the call fails because the role already exists, nothing to do.
// If the call fails because the user doesn't have permissions, then the role must be created outside of Copilot.
_ = o.iam.CreateECSServiceLinkedRole()
Copy link
Contributor

Choose a reason for hiding this comment

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

Are those the only two failure cases? Is it okay not to fail here due to permissions issues without surfacing any error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like it's fine because I don't' know what more we can do here for the user:
If the user doesn't have permission and the role was already created -> we don't want to fail.
If there was an internal error -> we don't want to fail.
For all other situations -> same behavior as today, it will print that the role is missing.

if _, err := c.client.CreateServiceLinkedRole(&iam.CreateServiceLinkedRoleInput{
AWSServiceName: aws.String(ecsServiceName),
}); err != nil {
return fmt.Errorf("create service linked role for Amazon ECS: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to wrap this error, since it a) doesn't ever get reported and b) will always be wrapped by other methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm good question 🤔, I think:
a) That should be up to the client to decide whether they want to ignore the error or handle it, so we should still return the error.
b) It's definitely odd reading: "create ECS service linked role: create ECS service linked role: AWS err"
I think we should still wrap but I'll change the data of this error message so that it's more specific to the input of the call:
"create service linked role for ecs.amazonaws.com: %w"

Copy link
Contributor

@bvtujo bvtujo left a comment

Choose a reason for hiding this comment

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

🚀

@mergify mergify bot merged commit 15b94a0 into aws:mainline Dec 11, 2020
@efekarakus efekarakus deleted the issues-1324 branch January 6, 2021 17:52
thrau pushed a commit to localstack/copilot-cli-local that referenced this pull request Dec 9, 2022
…ws#1749)

For accounts that never used ECS before, the [service linked role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using-service-linked-roles.html) does not exist which results in ECS not being able to create the cluster during `env init`.

This change attempts a best-effort creation of the role before creating the environment stack.

Resolves aws#1324


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to create a new environment if it's the first time to create an ECS cluster in an AWS account
3 participants