Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get request failing in boto3 python 3.8 lambda

I am trying to write a lambda function in 3.8 version but I am getting error while doing a get requests

[ERROR] AttributeError: module 'botocore.vendored.requests' has no attribute 'get' Traceback (most recent call last):   File "/var/task/lambda_function.py"

import json
from botocore.vendored import requests

def lambda_handler(event, context):

    request = event['Records'][0]['cf']['request']
    print (request)
    print(request['headers'])
    token = request['headers']['cookie'][0]['value'].partition("=")[2]
    print (token)
    print(type(request['uri']))
    consumer_id = request['uri'].rpartition('/')[-1]
    print (consumer_id)

    #Take the token and send it somewhere
    token_response = requests.get(url = 'https://url/api/files/'  + consumer_id, params = {'token': token})
    print (token_response)

    return request

I tried following this blog https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/

but not able to identify which layer to add. Could anyone please help

like image 672
cloudbud Avatar asked Jul 29 '26 04:07

cloudbud


1 Answers

According to the link you provided and assuming that request was correctly installed you should be using

import requests

instead of

from botocore.vendored import requests
like image 184
Marcin Avatar answered Jul 30 '26 19:07

Marcin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!