Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Lambda functions URLs #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions aws4.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/fast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down