Search code examples
pythonaws-lambdaauthorizationtoken

In AWS-Lambda(Python), how can I Invoke External API which needs Token Authorization in the header


I'm calling API in the AWS-Lambda(Python) function, but this external API needs a Token in the header. How should I configure/pass token in the header to my Lambda function?


Solution

  • I usually go for Python's requests module. It's not an included package in Lambda, so you'll need to package your function with the module included. Usually I need to include other modules, so little extra work. https://docs.aws.amazon.com/lambda/latest/dg/python-package.html

    Alternatively, you could use urllib/urllib3 which is already included. https://urllib3.readthedocs.io/en/latest/user-guide.html

    The documentation for both will explain how to set headers.