[Python] Send Post request to an external API using AWS Lambda in python

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I want to send a post request to an external API (https://example.com/api/jobs/test) every hour.

    The Lambda Function that I used is as follows:

    Handler: index.lambda_handler
    python: 3.6


    index.py

    import requests
    def lambda_handler(event, context):
    url="https://example.com/api/jobs/test"
    response = requests.post(url)
    print(response.text) #TEXT/HTML
    print(response.status_code, response.reason) #HTTP


    Test Event:

    {
    "url": "https://example.com/api/jobs/test"
    }


    Error:

    START RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d Version: $LATEST
    Unable to import module 'index': No module named 'requests'

    END RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d
    REPORT RequestId: 370eecb5-bfda-11e7-a2ed-373c1a03c17d Duration: 0.65 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 21 MB


    Any help would be appreciated.

    Continue reading...

Compartilhe esta Página