pulumi-aws: Pulumi does not detect failing lambdas during preview

Hello!

  • Vote on this issue by adding a 👍 reaction
  • If you want to implement this feature, comment to let us know (we’ll work with you on design, scheduling, etc.)

Issue details

Scenario:

  • Pulumi will fail randomly on a random lambda with the following error: error waiting for Lambda Function (panther-source-api) creation: InsufficientRolePermissions: The function’s execution role doesn’t have permission to perform this operation
  • even with that error, Pulumi will add it to the state as the function does return with ListFunction which is a new thing in the AWS world from what I’ve seen
  • In the AWS console, the function shows in the list of functions. Only when you click into the function, do you notice that the function actually failed deployment. See attached images
  • The only way forward is to go in as the deployment role and delete the function and re-run the deploy. Is there a way for Pulumi on a pulumi refresh to detect that a deployed lambda is in a failed state and mark it for replacement so a re-run of pulumi up will fix the situation without us having to manually intervene?

Affected area/feature

Pulumi Service, AWS provider

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 18 (11 by maintainers)

Most upvoted comments

I have been testing this situation by removing the sleep hack that had been necessary in the past and it’s no longer failing! I think something changed, maybe even on the AWS side. I have done this same exercise a number of times of the past years and it always failed, but now it seems to be working just fine. This issue may be resolve.

@guineveresaenger From what I can tell, aws.iam.Role is an asynchronous operation. I believe this to be the case because adding sleep(60) between role creation and lambda creation solves the problem, but if that sleep is not there, I get failures that the role has not been created (even though the lambda DependsOn the Role - so the lambda creation shouldn’t have started yet). This tells me that the role creation is returning success when it hasn’t finished yet.

Stress testing like this might help recreate the issue: https://www.pulumi.com/ai/conversations/1c0ec03b-7882-43dc-aa83-1bb2faceef83

I believe this is a classic case where basic tests seem to work because an async operation feels synchronous until the system is hammered.

@guineveresaenger We call the lambda as part of our Pulumi run (I wish we didn’t) - that likely explains why we see this error. I hadn’t considered this until now. I can’t speak for others in this thread.

We don’t see the problem at all because we have a sleep between all our role creations, but as soon as we remove the sleep it errors consistently. I’m on leave right now so I can’t provide a state file.

It sounds like the Lambda creation itself is eventually consistent and a solution would allow us to rely on the DependsOn for our lambda invocation that would wait to invoke the lambda until the lambda’s role/permissions are consistent.

Hi everyone!

I unfortunately still am unable to reproduce this behavior.

@grantjoy I tried running your suggestion both from scratch, and with a replace-update, and all resources were created successfully multiple times. Ordering of creation dependency looks correct (all necessary Roles and RolePolicyAttachments are created before the Lambda). This is not to say that this would never trigger this problem, but it’s not possible to root cause when the problem may never trigger.

A few more questions:

  • Can you tell us how often this is happening for you? Every deployment; every other deployment? Once a week? Which AWS region is this?
  • It would help to have a sample Statefile that includes the failed Lambda.

Further thoughts

The only reference to this particular error ( creation: InsufficientRolePermissions: The function’s execution role doesn’t have permission to perform this operation ) that I can find is in the upstream issue. It is not clear to me where this error message comes from. A lot of search results for execution role doesn’t have permission to perform this operation seem to point to a missing permission, not the Role itself. However those types of errors aren’t really provisioning errors; rather they’re errors on a properly deployed Lambda that can’t do a task.

The fact that a sleep() solves this issue for you does point to eventual consistency issues. Terraform has retry functionality aimed at addressing the eventual consistency of Roles. I notice that the error messages being processed do not match the one in this issue. We can add this error as a retry condition; but this assumes that the error is coming from the Lambda creation - if the lambda creation attempt does somehow “succeed” into a Failed state then this may not be the right answer. And the fact that the failed Lambda shows up in state seems to indicate that perhaps this is not the right approach.

I’m going to look at options more along the lines of the original suggestion with checking the state of a Lambda and allowing it to respond better to a pulumi refresh.

Thank you for your patience!

@guineveresaenger I think something like this could trigger it: https://www.pulumi.com/ai/conversations/5570d83e-2c42-48f3-bd59-9aae2d272ac9

This example may need to be extended to run many more roles/lambdas to simulate a stress test where roles take longer to create.

It would be awesome if the aws.iam.Role function had another parameter that checked if the role actually created before returning and continuing.

@squaremo conveying info from a zendesk ticket https://pulumi.zendesk.com/agent/tickets/2181. Agree that the failure cause isn’t so important, just that failing lambdas be detected.