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

Compatible with serverless v3.0 #77

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Optionally add custom configuration properties:
custom:
deploymentBucket:
versioning: true
accelerate: true
blockPublicAccess: true
tags:
- Key: Environment
Expand All @@ -85,7 +84,6 @@ custom:
| Property | Required | Type | Default | Description |
|---------------------|----------|-----------|---------|---------------------------------------------------|
| `versioning` | `false` | `boolean` | `false` | Enable versioning on the deployment bucket |
| `accelerate` | `false` | `boolean` | `false` | Enable acceleration on the deployment bucket |
| `enabled` | `false` | `boolean` | `true` | Enable this plugin |
| `policy` | `false` | `string` | | Bucket policy as JSON |
| `tags` | `false` | `array` | | Bucket tags as an array of key:value objects |
Expand Down
3 changes: 2 additions & 1 deletion example/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
service: example-service

frameworkVersion: '3'

provider:
name: aws
runtime: nodejs12.x
Expand All @@ -15,7 +17,6 @@ plugins:
custom:
deploymentBucket:
versioning: false
accelerate: true
policy: "${file(bucket-policy.json)}"
blockPublicAccess: true
tags:
Expand Down
39 changes: 0 additions & 39 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DeploymentBucketPlugin {
if (this.deploymentBucket.name) {
this.config.versioning = get(this.config, 'versioning', false)
this.config.accessLog = get(this.config, 'accessLog', false)
this.config.accelerate = get(this.config, 'accelerate', false)
this.config.policy = get(this.config, 'policy', undefined)
this.config.tags = util.filterValidBucketTags(get(this.config, 'tags', undefined))
this.config.blockPublicAccess = get(this.config, 'blockPublicAccess', undefined)
Expand Down Expand Up @@ -180,34 +179,6 @@ class DeploymentBucketPlugin {

}

async hasBucketAcceleration (name) {
const params = {
Bucket: name
};

try {
const response = await this.provider.request('S3', 'getBucketAccelerateConfiguration', params)
if (response.Status && response.Status == 'Enabled') {
return true
}

return false
} catch (e) {
return false
}
}

async putBucketAcceleration(name, status) {
const params = {
Bucket: name,
AccelerateConfiguration: {
Status: status ? 'Enabled' : 'Suspended'
}
};

return await this.provider.request('S3', 'putBucketAccelerateConfiguration', params)
}

async putBucketPolicy(name, policy) {
const params = {
Bucket: name,
Expand Down Expand Up @@ -299,16 +270,6 @@ class DeploymentBucketPlugin {
}
}

if ((await this.hasBucketAcceleration(this.deploymentBucket.name)) != this.config.accelerate) {
await this.putBucketAcceleration(this.deploymentBucket.name, this.config.accelerate)

if (this.config.accelerate) {
this.serverless.cli.log('Enabled acceleration on deployment bucket')
} else {
this.serverless.cli.log('Suspended acceleration on deployment bucket')
}
}

if (this.config.policy) {
await this.putBucketPolicy(this.deploymentBucket.name, this.config.policy)
this.serverless.cli.log(`Applied deployment bucket policy`)
Expand Down
Loading