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
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.
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.
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.
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.

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?