While trying to start and stop RDS instances with boto3 on AWS Lambda, I am getting an interesting error - 'RDS' object has no attribute 'stop_db_instance': AttributeError
Even the simplest code throws this error, e.g.
import boto3
def lambda_handler(event, context):
boto3.client('rds').stop_db_instance(DBInstanceIdentifier='myInstanceID')
I am using python3.6 runtime, so as per information available on this page, boto3 1.4.4 should be available (which I assume already has proper methods - https://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.stop_db_instance)
Any suggestions are appreciates!
Lambda can work seamlessly with RDS instances, as long as you remember the specific requirements for this particular setup. Since RDS instances are running in your VPC and Lambda by default does not have access to those resources, you'll need to configure the VPC connection when creating a Lambda function.
Stopping and starting a database instance requires just a few clicks in the AWS Management Console, or a single call using the AWS API or AWS Command Line Interface, and takes just a few minutes.
I was using boto3==1.4.1
and botocore==1.4.64
and receving same error as yours both locally and on lambda.
AWS Lambda must be using old botocore library. I tried using boto3==1.4.4
and botocore==1.5.75
and it worked.
Therefore, decided to upload my own zip containing latest boto3 and botocore(mentioned above) and it works.
Creating a Deployment Package
UPDATE
Here is my aws lambda code snippet -
import botocore
import boto3
def lambda_handler(event, context):
print("Version is {}".format(botocore.__version__))
boto3.client('rds').stop_db_instance(DBInstanceIdentifier='myInstanceID')
output
: Version is 1.5.52
and 1.5.52 is responsible for not having stop_db_instance
attribute in rds module. So, manually creating zip having the latest version will do the trick .
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With