Reputation: 197
I am trying to create a lambda function on AWS to start and stop an EC2 instance, but it's giving the following error
botocore.exceptions.ClientError: An error occurred (UnauthorizedOperation) when calling the StartInstances operation: You are not authorized to perform this operation.
What are the steps which should I take to stop this error? I am not a developer, just trying to run some ML model via EC2. I read something on creating an IAM role, which I did with full EC2 access, but I am not sure how to use the same in the lambda function. Can anyone guide me on the same?
Upvotes: 1
Views: 464
Reputation: 269480
When creating an AWS Lambda function, you assign an IAM Role to the function.
When the function makes an AWS API call, it uses the permissions provided in the IAM Role to call other AWS services.
Therefore, you should:
Your function would need, at minimum, the ec2:StartInstances
permission. It's likely that it will need other permissions too, depending upon the settings used when launching an instance.
Upvotes: 8