Skip to content

Commit

Permalink
fix(s3): bugfixing the s3 endpoint parser (#3650)
Browse files Browse the repository at this point in the history
* fix: allow s3 to make requests to s3 object lambda when passed into the arn
  • Loading branch information
alexforsyth authored Feb 26, 2021
1 parent 13d3852 commit a2e71ca
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "s3",
"description": "Bugfixing the s3 arn endpoint parser"
}
14 changes: 13 additions & 1 deletion lib/services/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ AWS.util.update(AWS.S3.prototype, {
var accessPointArn = req.service._parsedArn;

var isOutpostArn = accessPointArn.service === 's3-outposts';
var isObjectLambdaArn = accessPointArn.service === 's3-object-lambda';

var outpostsSuffix = isOutpostArn ? '.' + accessPointArn.outpostId: '';
var serviceName = isOutpostArn ? 's3-outposts': 's3-accesspoint';
Expand All @@ -356,8 +357,19 @@ AWS.util.update(AWS.S3.prototype, {
useArnRegion ? accessPointArn.region : req.service.config.region,
dnsSuffix
].join('.');
endpoint.host = endpoint.hostname;

if (isObjectLambdaArn) {
// should be in the format: "accesspoint/${accesspointName}"
var serviceName = 's3-object-lambda';
var accesspointName = accessPointArn.resource.split('/')[1];
endpoint.hostname = [
accesspointName + '-' + accessPointArn.accountId,
serviceName,
useArnRegion ? accessPointArn.region : req.service.config.region,
dnsSuffix
].join('.');
}
endpoint.host = endpoint.hostname;
var encodedArn = AWS.util.uriEscape(req.params.Bucket);
var path = req.httpRequest.path;
//remove the Bucket value from path
Expand Down
6 changes: 4 additions & 2 deletions lib/services/s3util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ var s3util = {
validateArnService: function validateArnService(req) {
var parsedArn = req.service._parsedArn;

if (parsedArn.service !== 's3' && parsedArn.service !== 's3-outposts') {
if (parsedArn.service !== 's3'
&& parsedArn.service !== 's3-outposts'
&& parsedArn.service !== 's3-object-lambda') {
throw AWS.util.error(new Error(), {
code: 'InvalidARN',
message: 'expect \'s3\' or \'s3-outposts\' in ARN service component'
message: 'expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component'
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@
"helper-test": "mocha scripts/lib/test-helper.spec.js",
"csm-functional-test": "mocha test/publisher/functional_test"
}
}
}
12 changes: 6 additions & 6 deletions scripts/region-checker/allowlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ var allowlist = {
248,
261,
267,
630,
632,
751,
762,
642,
644,
763,
764,
769
774,
775,
776,
781
]
};

Expand Down
2 changes: 1 addition & 1 deletion test/services/s3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3487,7 +3487,7 @@ describe('AWS.S3', function() {
request.send(function(err, data) {
expect(err).to.exist;
expect(err.name).to.equal('InvalidARN');
expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' in ARN service component');
expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component');
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/services/s3control.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('AWS.S3Control', function() {
request.send(function(err, data) {
expect(err).to.exist;
expect(err.name).to.equal('InvalidARN');
expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' in ARN service component');
expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component');
done();
});
});
Expand Down

0 comments on commit a2e71ca

Please sign in to comment.