Skip to content

Instantly share code, notes, and snippets.

@lusentis
Last active January 31, 2017 11:08
Show Gist options
  • Save lusentis/e68a81c5e0d5340bf059d386cf46f5df to your computer and use it in GitHub Desktop.
Save lusentis/e68a81c5e0d5340bf059d386cf46f5df to your computer and use it in GitHub Desktop.
parses an Amazon S3 URL and returns bucket, region and key
function parseS3URL(url) {
const tokens = /^https:\/\/([\w\d-]+)\.s3(-(\w\w-\w+-\d))?\.amazonaws\.com\/(.*?)((#|%23).*)?$/.exec(
url
);
if (!tokens) {
return false;
}
const [, bucket, , region = 'us-east-1', key] = tokens;
return { bucket, region, key };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment