diff --git a/aws4.js b/aws4.js index b0cfb7c..baca9a9 100644 --- a/aws4.js +++ b/aws4.js @@ -55,8 +55,9 @@ function RequestSigner(request, credentials) { this.service = request.service || hostParts[0] || '' this.region = request.region || hostParts[1] || 'us-east-1' - // SES uses a different domain from the service name + // Services that use a different domain from the service name if (this.service === 'email') this.service = 'ses' + if (this.service === 'lambda-url') this.service = 'lambda' if (!request.method && request.body) request.method = 'POST' @@ -78,7 +79,7 @@ function RequestSigner(request, credentials) { } RequestSigner.prototype.matchHost = function(host) { - var match = (host || '').match(/([^\.]+)\.(?:([^\.]*)\.)?amazonaws\.com(\.cn)?$/) + var match = (host || '').match(/([^\.]+)\.(?:([^\.]*)\.)?(amazonaws\.com(\.cn)?|on.aws)$/) var hostParts = (match || []).slice(1, 3) // ES's hostParts are sometimes the other way round, if the value that is expected diff --git a/test/fast.js b/test/fast.js index 171c115..a08fcb3 100644 --- a/test/fast.js +++ b/test/fast.js @@ -40,6 +40,12 @@ describe('aws4', function() { signer.region.should.equal('us-west-2') }) + it('should correctly recognise lambda for function urls', function() { + var signer = new RequestSigner('https://long-url-id.lambda-url.eu-west-1.on.aws/hello/world') + signer.service.should.equal('lambda') + signer.region.should.equal('eu-west-1') + }) + it('should correctly recognise es when interacting directly with the es api', function() { var signer = new RequestSigner('https://search-cluster-name-aaaaaa0aa00aa0aaaaaaa00aaa.eu-west-1.es.amazonaws.com') signer.service.should.equal('es')