Could you share some snippet code for the lambda@edge rewrite @jonsmirl?
I managed to add the authorization header using aws4 but the Lambda Custom Origin is returning the error:
504 ERROR
The request could not be satisfied.
CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection.
For more information on how to troubleshoot this error, please refer to the CloudFront documentation (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/http-504-gateway-timeout.html).
//lamba@edge requestRewriter.js
const aws4 = require('aws4');
exports.handler = function (event, context, callback) {
const request = event.Records[0].cf.request;
let opts = aws4.sign({
service: 'lambda',
method: 'POST',
path: '/2015-03-31/functions/myFunc/invocations',
}, {
accessKeyId: 'MY_ACCESS_KEY',
secretAccessKey: 'MY_SECRET_KEY',
});
request.method = opts.method;
request.uri = opts.path;
request.headers = Object.keys(opts.headers).reduce((headers, key) => {
if (key !== 'Host') {
headers[key.toLowerCase()] = [{
key,
value: opts.headers[key]
}];
}
return headers;
}, {
host: request.headers.host
});
callback(null, request);
};