I have inherited a python lambda which I need to convert to node js. I am a bit stuck with the code that handles authentication and so I am wondering what the JS equivalent would be for the python code below:
import boto3
import json
import requests
from requests_aws4auth import AWS4Auth
region = "eu-west-2"
service = "es"
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)
r = requests.get(url, auth=awsauth)
Here is my work in progress at what seem to be relevant calls using the javascript aws-sdk:
import AWS from "aws-sdk"
const region = "eu-west-2"
const service = "es"
const credentials = AWS.Credentials().get()
const response = await fetch(url, {
headers: { Authorization: credentials },
credentials: "include"
})
I know the python code works, so I just need to convert it to JS. As you can see I'm not really sure what to do with credentials once I have it or what the equivalent of auth=awsauth would be within the fetch call. Any help would be much appreciated. Thank you!