Using aws4
This example shows how to use AWS4 module.
aws4
module is imported as aws4
Call AWS Lambda function
// Set your AWS credentials
const accessKeyId = '<access key ID>';
const secretAccessKey = '<secret access key>';
// Set the AWS region
const region = 'eu-central-1'; // Replace with your AWS region
// Set the AWS service name (e.g., 's3', 'lambda', etc.)
const service = 'lambda';
const serviceUrl = '<service ID>.lambda-url.eu-central-1.on.aws';
// Set the request parameters
const options = {
host: serviceUrl,
path: '/', // Replace with your API endpoint
method: 'GET', // HTTP method (GET, POST, PUT, etc.)
region,
service,
headers: {
'Content-Type': 'application/json', // Set any required headers
},
};
// Sign the request using AWS Signature Version 4
aws4.sign(options, {
accessKeyId,
secretAccessKey,
region,
service: serviceName,
});
// use fetch to get response from service
const response = await fetch(`https://${serviceUrl}`, {
method: request.method,
headers: request.headers,
});
See aws4 github page for full examples.