Skip to content

Commit

Permalink
fix(AWS Deploy): Fix handling of deployment bucket extensions (#10137)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars-lan committed Oct 25, 2021
1 parent b7a6349 commit 39bdea0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 42 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -12,7 +12,7 @@

**The Serverless Framework** – Build applications on AWS Lambda and other next-gen cloud services, that auto-scale and only charge you when they run. This lowers the total cost of running and operating your apps, enabling you to build more and manage less.

The Serverless Framework is a command-line tool that uses easy and approachable YAML syntax to deploy both your code and cloud infrastructure needed to make tons of serverless application use-cases. It's a multi-language framework that supports Node.js, Typescript, Python, Go, Java, and more. It's also completely extensible via over 1,000 plugins that can add more serverless use-cases and workflows to the Framework.
The Serverless Framework is a command-line tool that uses easy and approachable YAML syntax to deploy both your code and cloud infrastructure needed to make tons of serverless application use-cases. It's a multi-language framework that supports Node.js, Typescript, Python, Go, Java, and more. It's also completely extensible via over 1,000 plugins that can add more serverless use-cases and workflows to the Framework.

Actively maintained by [Serverless Inc](https://www.serverless.com).

Expand All @@ -37,11 +37,11 @@ npm install -g serverless

### Set Up Your AWS Account Credentials.

The Serverless Framework deploys to your own AWS account. You'll need to enable Serverless Framework to deploy to your AWS account by giving it access. [Here is a guide to help you set up your credentials securely](https://www.serverless.com/framework/docs/providers/aws/guide/credentials)
The Serverless Framework deploys to your own AWS account. You'll need to enable Serverless Framework to deploy to your AWS account by giving it access. [Here is a guide to help you set up your credentials securely](https://www.serverless.com/framework/docs/providers/aws/guide/credentials)

### Create A Service:

A "Service" is the Framework's project or app concept. You can create one from scratch or select an existing template by running...
A "Service" is the Framework's project or app concept. You can create one from scratch or select an existing template by running...

```bash
serverless
Expand Down
27 changes: 10 additions & 17 deletions lib/plugins/aws/package/lib/generateCoreTemplate.js
Expand Up @@ -45,29 +45,22 @@ module.exports = {

// enable S3 block public access for deployment bucket
if (deploymentBucketObject.blockPublicAccess) {
Object.assign(
this.serverless.service.provider.compiledCloudFormationTemplate.Resources[
deploymentBucketLogicalId
].Properties,
{
PublicAccessBlockConfiguration: {
BlockPublicAcls: true,
BlockPublicPolicy: true,
IgnorePublicAcls: true,
RestrictPublicBuckets: true,
},
}
);
this.serverless.service.provider.compiledCloudFormationTemplate.Resources[
deploymentBucketLogicalId
].Properties.PublicAccessBlockConfiguration = {
BlockPublicAcls: true,
BlockPublicPolicy: true,
IgnorePublicAcls: true,
RestrictPublicBuckets: true,
};
}

// enable S3 bucket versioning
if (deploymentBucketObject.versioning) {
this.serverless.service.provider.compiledCloudFormationTemplate.Resources[
deploymentBucketLogicalId
].Properties = {
VersioningConfiguration: {
Status: 'Enabled',
},
].Properties.VersioningConfiguration = {
Status: 'Enabled',
};
}

Expand Down
27 changes: 5 additions & 22 deletions test/unit/lib/plugins/aws/package/lib/generateCoreTemplate.test.js
Expand Up @@ -72,14 +72,15 @@ describe('#generateCoreTemplate()', () => {
});
});

it('should enable S3 Block Public Access if specified', () =>
it('should enable S3 Block Public Access & versioning if specified', () =>
runServerless({
config: {
service: 'irrelevant',
provider: {
name: 'aws',
deploymentBucket: {
blockPublicAccess: true,
versioning: true,
},
},
},
Expand All @@ -92,30 +93,12 @@ describe('#generateCoreTemplate()', () => {
IgnorePublicAcls: true,
RestrictPublicBuckets: true,
},
VersioningConfiguration: {
Status: 'Enabled',
},
});
}));

it('should enable S3 bucket versioning if specified', async () => {
const { cfTemplate } = await runServerless({
config: {
service: 'irrelevant',
provider: {
name: 'aws',
deploymentBucket: {
versioning: true,
},
},
},
command: 'package',
});

expect(cfTemplate.Resources.ServerlessDeploymentBucket.Properties).to.deep.include({
VersioningConfiguration: {
Status: 'Enabled',
},
});
});

it('should add resource tags to the bucket if present', () =>
runServerless({
config: {
Expand Down

0 comments on commit 39bdea0

Please sign in to comment.