How Can I Invoke a New Lambda from an Old One Without New IAM Roles?

0
44
Asked By TechMaverick42 On

I'm trying to call a new AWS Lambda function from an existing one using Boto3, but I'm facing some restrictions. I've already added the invoke function policy in the CloudFormation template for the existing Lambda. However, I'm unsure how to invoke the new Lambda from my old Lambda's code while working on a Cloud9 instance. The catch is that I can't assign a new IAM role to my EC2 instance. Any suggestions on how to tackle this?

4 Answers

Answered By LambdaProUser99 On

If you can't assign a new IAM role, you can expose your Lambda via an HTTP URL. However, that method would require you to call the Lambda synchronously by default. To implement asynchronous invocation, you’d set the `InvocationType` to `Event` when calling it through Boto3. Just make sure your old Lambda has the necessary permissions to call the new one.

CleverCoder77 -

I attempted the HTTP URL method, but it seems to run synchronously first, resulting in timeouts. Is there a way to configure it for asynchronous execution?

Answered By CloudWizard88 On

Have you considered using AWS Step Functions? It might be a better fit for your needs, especially if you’re looking to manage multiple Lambda executions and dependencies. Just keep in mind that Step Functions would generally also require an IAM role for your EC2 instance.

Answered By CodeGuru88 On

Just a reminder, if you deploy your code directly from Cloud9 for invoking the new Lambda, your existing Lambda needs to have the correct permissions set to invoke it. Without that IAM role attached to your EC2 instance, invoking Lambda locally through Cloud9 will be tricky.

Answered By AWSWhisperer101 On

To use Boto3 for invoking the Lambda, you can set it up in Python as follows: use the `invoke` method with the `InvocationType` set to `Event` for async invocation. Ensure your existing Lambda has the right permissions to call the new Lambda. You’ll also need the new Lambda’s ARN to send a request.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.