npm install
You can access data in Amazon S3 through a Multi-Region Access Point (MRAP) using the hostname of the Multi-Region Access Point.
The hostname for the request is <MRAP_alias>.accesspoint.s3-global.amazonaws.com. For more details, see Multi-Region Access Point hostnames.
- If all you need is to get the headers with most common config.
- If you need high customization.
- Full example to get signed headers and make an API call.
If all you need is to get the headers with most common config, use sigV4ASignBasic(method, endpoint, service).
const { sigV4ASignBasic } = require('./sigv4a_sign')
var method = 'GET';
var endpoint = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>';
var service = 's3';
// function from ./sigv4a_sign.js
var headers = sigV4ASignBasic(method, endpoint, service);
console.log(headers._flatten());If you need high customization, use sigV4ASign(method, endpoint, config = crt.auth.AwsSigningConfig).
const { sigV4ASign } = require('./sigv4a_sign')
const crt = require("aws-crt")
var config = {
service: 's3',
region: '*',
algorithm: crt.auth.AwsSigningAlgorithm.SigV4Asymmetric,
signature_type: crt.auth.AwsSignatureType.HttpRequestViaHeaders,
signed_body_header: crt.auth.AwsSignedBodyHeaderType.XAmzContentSha256,
provider: crt.auth.AwsCredentialsProvider.newDefault()
};
var method = 'GET';
var endpoint = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>';
// function from ./sigv4a_sign.js
var headers = sigV4ASign(method, endpoint, config);
console.log(headers._flatten());Full example to get signed headers and make an API call.
const { sigV4ASignBasic } = require('./sigv4a_sign')
const https = require('https');
var method = 'GET';
var endpoint = 'https://<MRAP_alias>.accesspoint.s3-global.amazonaws.com/<s3-object-key>';
var service = 's3';
// function from ./sigv4a_sign.js
var headers = sigV4ASignBasic(method, endpoint, service);
const options = {
hostname: headers.get('host'),
path: new URL(endpoint).pathname,
method: 'GET',
headers: headers._flatten()
}
const req = https.request(options, res => {
res.on('data', d => {
process.stdout.write(d);
})
}).on('error', error => {
console.error(error)
}).end()