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

PreCreatedIAMRole no longer working in 1.2.0 #793

Closed
kadrach opened this issue Apr 11, 2018 · 3 comments
Closed

PreCreatedIAMRole no longer working in 1.2.0 #793

kadrach opened this issue Apr 11, 2018 · 3 comments
Labels

Comments

@kadrach
Copy link
Member

kadrach commented Apr 11, 2018

$ chalice --version
chalice 1.2.0
$ chalice new-project hello-world && cd hello-world

Add to .chalice/config.json:

{
  "version": "2.0",
  "app_name": "hello-world",
  "manage_iam_role": false,
  "iam_role_arn": "arn:aws:iam::123456789012:role/some-lambda-role",
  "stages": {
    "dev": {
      "api_gateway_stage": "api"
    }
  }
}
$ chalice package out
Creating deployment package.
Traceback (most recent call last):
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/chalice/cli/__init__.py", line 357, in main
    return cli(obj={})
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/chalice/cli/__init__.py", line 286, in package
    packager.package_app(config, out, stage)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/chalice/package.py", line 290, in package_app
    resources)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/chalice/package.py", line 82, in generate_sam_template
    handler(resource, template)
  File "/home/kadrach/.pyenv/versions/3.6.4/lib/python3.6/site-packages/chalice/package.py", line 251, in _default
    raise NotImplementedError(resource)
NotImplementedError: PreCreatedIAMRole(role_arn='arn:aws:iam::123456789012:role/some-lambda-role')

This used to be implemented, and I can't find any mention of it in the changelog, so assume this is a bug :)

@stealthycoin
Copy link
Contributor

Looks like a bug to me.

@kadrach
Copy link
Member Author

kadrach commented Apr 12, 2018

This stems from the fact that PrecreatedIAMRole is identified by the dependency builder as a dependency, causing the packager to want to "generate" it. A quick fix is a noop generator:

diff --git chalice/package.py chalice/package.py                
index c42da85..99c28fa 100644                                   
--- chalice/package.py                                          
+++ chalice/package.py                                          
@@ -82,6 +82,11 @@ class SAMTemplateGenerator(object):          
             handler(resource, template)                        
         return template                                        
                                                                
+    def _generate_precreatediamrole(self, resource, template): 
+        # type: (models.ScheduledEvent, Dict[str, Any]) -> None
+        # Nothing we need to do here                           
+        pass                                                   
+                                                               
     def _generate_scheduledevent(self, resource, template):    
         # type: (models.ScheduledEvent, Dict[str, Any]) -> None
         function_cfn_name = to_cfn_resource_name(                          

The packager should probably not try to generate a PrecreatedIAMRole in the first place (I suppose it's more of a parameter? Though CF thinks of it as a dependency), but I don't have a good understanding of the planning stage at the moment.

@jamesls
Copy link
Member

jamesls commented Apr 12, 2018

@kadrach Yep that's exactly it, thanks for looking into it.

jamesls added a commit to jamesls/chalice that referenced this issue Apr 12, 2018
We need a noop method for precreated roles in the template generator.
This was missed in testing because the models were directly
passed to the template generator instead of using the
dependency builder.  In this case we were only passing the
LambdaFunction resource to the template generator, but
in reality we'd also pass the `models.IAMRole` resource
as well because it's a dependency of the lambda function.

Fixes aws#793.
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

3 participants