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

After fail to create IAM role, cannot deploy anymore. #565

Closed
chroju opened this issue Oct 7, 2017 · 12 comments
Closed

After fail to create IAM role, cannot deploy anymore. #565

chroju opened this issue Oct 7, 2017 · 12 comments
Labels

Comments

@chroju
Copy link

chroju commented Oct 7, 2017

Hello.

When I execute chalice deploy, faced error of IAM role.

$ chalice deploy --no-autogen-policy
Creating role: sample-chalice
ERROR - While deploying your chalice application, received the following error:

 An error occurred (MalformedPolicyDocument) when calling the PutRolePolicy
 operation: Syntax errors in policy.

and I have fixed syntax error, deploy again.
However, the IAM role had been made incompletely by the last deploy, so the deploy failed with another error.

$ chalice deploy --no-autogen-policy
Updating IAM policy for role: sample-chalice
ERROR - While deploying your chalice application, received the following error:

 An error occurred (NoSuchEntity) when calling the DeleteRolePolicy operation:
 The role policy with name sample-chalice cannot be found.

If I wanted deploy to succeed, I had to delete incomplete IAM role once with AWS console or AWS CLI. chalice delete command was useless in this case.

Is this as you expected ?

environment

  • chalice 1.0.3
  • Python 3.6.1
@jamesls
Copy link
Member

jamesls commented Oct 10, 2017

Thanks for reporting, this is a bug. We'll get this fixed.

@jamesls jamesls added the bug label Oct 10, 2017
This was referenced Dec 6, 2017
jamesls pushed a commit that referenced this issue Dec 14, 2017
Fixes bug #565.

So there ended up being a couple issue that I fixed here, first being bug #565
which was fixed by making a change to the awsclient.py file.

The second issue that I discovered while working on this bug was the following.
If you do:

```
$ chalice new-project muck
$ cd muck
$ chalice deploy --no-autogen-policy
```

The same bug happens because the policy-env.json file does not exist. This
results in a policy document of:

```
"Version": "2012-10-17",
"Statement": []
```

being uploaded which throws a MalformedPolicyDocument error. In order to fix
this issue I made changes to the deployer.py file. I removed the default policy
and now raise a RuntimeError and alert the user to the fact that they do not
have a policy-env.json file.

The last change that I made was to handle malformed json by adding nicer
logging modeled after the config file loader.
@jamesls
Copy link
Member

jamesls commented Dec 14, 2017

Fixed via #636

@jamesls jamesls closed this as completed Dec 14, 2017
@abdullah353
Copy link

I have started the app using chalice and stucked, the steps that i did on EC2 ubuntu instance were following:

ubuntu@ip-172-31-44-209:~$ chalice new-project traindexServiceAPI
ubuntu@ip-172-31-44-209:~$ cd traindexServiceAPI/
ubuntu@ip-172-31-44-209:~/traindexServiceAPI$ chalice deploy
Creating role: traindexServiceAPI-dev
ERROR - While deploying your chalice application, received the following error:

 An error occurred (AccessDenied) when calling the CreateRole operation: User: 
 arn:aws:iam::xxxxx:user/devop is not authorized to perform: 
 iam:CreateRole on resource: arn:aws:iam::xxxxx:role/traindexServiceAPI-
 dev

# After allowing iam:CreateRole from AWS Console. 
ubuntu@ip-172-31-44-209:~/traindexServiceAPI$ chalice deploy
Creating role: traindexServiceAPI-dev
ERROR - While deploying your chalice application, received the following error:

 An error occurred (AccessDenied) when calling the PutRolePolicy operation: 
 User: arn:aws:iam::xxxxx:user/devop is not authorized to perform: 
 iam:PutRolePolicy on resource: role traindexServiceAPI-dev

# After allowing iam:PutRolePolicy from AWS Console. 
ubuntu@ip-172-31-44-209:~/traindexServiceAPI$ chalice deploy

The following actions will be added to the execution policy:

logs:PutLogEvents
logs:CreateLogGroup
logs:CreateLogStream

Would you like to continue?  [Y/n]: Y
Updating IAM policy for role: traindexServiceAPI-dev
ERROR - While deploying your chalice application, received the following error:

 An error occurred (AccessDenied) when calling the DeleteRolePolicy operation: 
 User: arn:aws:iam::xxxxx:user/devop is not authorized to perform: 
 iam:DeleteRolePolicy on resource: role traindexServiceAPI-dev

@aalvrz
Copy link
Contributor

aalvrz commented Dec 18, 2017

I am still experiencing the same issue when deploying:

Updating IAM policy for role: <role>
ERROR - While deploying your chalice application, received the following error:

 An error occurred (NoSuchEntity) when calling the DeleteRolePolicy operation: 
 The role policy with name <role> cannot be found.

I don't understand why Chalice is still trying to delete the role on deployment...?

I cannot seem to be able to fix this, since the role doesn't exist in AWS. Therefore I cannot even remove it with the console...

@ericzbeard
Copy link

I'm getting the same error using the latest version.

@ericzbeard
Copy link

A quick workaround is to manually create the inline policy using the name from the error message.

@hatdropper1977
Copy link

FWIW I receive the same error as well.

@owenbrown
Copy link

Fixing this error is important to me.

@kotowick
Copy link

Is there still no fix?

@chroju
Copy link
Author

chroju commented Mar 6, 2018

This issue is what I was open, and I have confirmed that the phenomenon I reported was fixed via #636. Under what situation do you still encounter the same error ?

@ericzbeard
Copy link

I still see this in chalice 1.1.0, and I can't upgrade to 1.3.0 since it requires an older version of pip.

pkg_resources.DistributionNotFound: The 'pip==9.0.1' distribution was not found and is required by the application

A reminder on the workaround in case anyone else stumbles across this: there should be a role called {your-app-name} with a policy under it called {your-app-name}. If they don't exist, create them. It doesn't matter what the policy does, since chalice will delete it.

@milescrawford
Copy link

This is not fixed. Another way this happens is if chalice SUCCESSFULLY deletes the role, but does so when deploying in an environment that does not update the stored (in github, outside a docker container, etc) .chalice/deployed<STAGE>.json file.

Then, the metadata in the file doesn't match reality and it attempts to delete every time you deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants