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

Tag support #96

Merged
merged 3 commits into from
Jun 21, 2020
Merged
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -76,6 +76,24 @@ Use this parameter to specify a unique name for the S3 bucket that your files wi
---
**tags**
_optional_, default: `none`

```yaml
custom:
client:
...
tags:
tagKey: tagvalue
tagKey2: tagValue2
...
```

Use this parameter to specify a list of tags as key:value pairs that will be assigned to your bucket.

---

**distributionFolder**

_optional_, default: `client/dist`
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -130,7 +130,8 @@ class Client {
keyPrefix,
sse,
routingRules,
manageResources;
manageResources,
tags;

return this._validateConfig()
.then(() => {
@@ -160,6 +161,7 @@ class Client {
errorDoc = this.options.errorDocument || 'error.html';
redirectAllRequestsTo = this.options.redirectAllRequestsTo || null;
routingRules = this.options.routingRules || null;
tags = this.options.tags || []

const deployDescribe = ['This deployment will:'];

@@ -236,6 +238,14 @@ class Client {
bucketPolicyFile && JSON.parse(fs.readFileSync(bucketPolicyFile));
return configure.configurePolicyForBucket(this.aws, bucketName, customPolicy);
})
.then(() => {
if (tags.length === 0) {
this.serverless.cli.log(`Retaining existing tags...`);
return Promise.resolve();
}
this.serverless.cli.log(`Configuring tags for bucket...`);
return configure.configureTagsForBucket(this.aws, bucketName, tags);
})
.then(() => {
if (this.cliOptions['cors-change'] === false || manageResources === false) {
this.serverless.cli.log(`Retaining existing bucket CORS configuration...`);
20 changes: 19 additions & 1 deletion lib/configure.js
Original file line number Diff line number Diff line change
@@ -127,8 +127,26 @@ function configureCorsForBucket(aws, bucketName) {
return aws.request('S3', 'putBucketCors', params);
}

/**
* Configures Tags for given bucket
* @param {Object} aws - AWS class
* @param {string} bucketName - Name of bucket to be configured
*/
function configureTagsForBucket(aws, bucketName, tags) {
const tagData = Object.keys(tags).map((key,index) => { return { Key:key,Value:tags[key] } })
const tagSet = { "TagSet": tagData }

const params = {
Bucket: bucketName,
Tagging: tagSet
};

return aws.request('S3', 'putBucketTagging', params);
}

module.exports = {
configureBucket,
configureCorsForBucket,
configurePolicyForBucket
configurePolicyForBucket,
configureTagsForBucket
};