If you use request library from boto then most of time it will give error in aws lambda as this is excluded in newer version of aws python packages.
If you use below import in your lambda in latest python package you will get below mentioned error
from botocore.vendored import requests
No module named 'requests'
so in new python module below library is provided which you can use for rest api communication.
urllib3
I was facing problem while calling api with botocore.vendored.request so i have used below code to solve my issue with urllib3
def callApi():
print('calling service')
import callApi
http = urllib3.PoolManager()
response = http.request('POST',
'http://emailmicroservice-env.eba-uaftkpbu.us-east-1.elasticbeanstalk.com/v1/sendEmail',
body = json.dumps({ "to":"test1@gmail.com", "from":"test2.com", "subject":"AWS micro service testing", "name":"Sagar", "product":"Debit card", "link":"www.google.com", "templateType":"thankyou.ftl"}),
headers = {'Content-Type': 'application/json'},
retries = False)
data = json.loads(response.data.decode('utf-8'))
print('data' , data)
print('response.data',response.data)
def lambda_handler(event, context):
callApi()
Here lambda_handler is entry point for your lambda and then it will call callApi() method and using urllib3 it will give call to rest webservice.
For more details please refer