Skip to content

Commit

Permalink
feat(CLI): Introduce deprecation on S3 Accelerate for user bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 15, 2021
1 parent d2a75ea commit 04b921a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
8 changes: 8 additions & 0 deletions docs/deprecations.md
Expand Up @@ -36,6 +36,14 @@ Note:
- In service configuration setting is ineffective for deprecations reported before service configuration is read.
- `SLS_DEPRECATION_DISABLE` env var and `disabledDeprecations` configuration setting remain respected, and no errors will be thrown for mentioned deprecation coodes.

<a name="S3_TRANSFER_ACCELERATION_ON_EXISTING_BUCKET"><div>&nbsp;</div></a>

## Attempt to enable S3 Transfer Acceleration on provided S3 buckets

Deprecation code: `S3_TRANSFER_ACCELERATION_ON_EXISTING_BUCKET`

Starting with "v3.0.0", attempt to enable S3 Transfer Acceleration on user provided bucket will result in error instead of a warning. To ensure seamless upgrade, please stop using "--aws-s3-accelerate" flag.

<a name="DUPLICATE_PLUGIN_DEFINITION"><div>&nbsp;</div></a>

## Duplicate plugin definition in configuration
Expand Down
7 changes: 4 additions & 3 deletions lib/plugins/aws/package/lib/generateCoreTemplate.js
Expand Up @@ -3,7 +3,6 @@
const path = require('path');
const _ = require('lodash');
const ServerlessError = require('../../../../serverless-error');
const { legacy, log } = require('@serverless/utils/log');

module.exports = {
generateCoreTemplate() {
Expand Down Expand Up @@ -94,8 +93,10 @@ module.exports = {

if (bucketName) {
if (isS3TransferAccelerationEnabled) {
legacy.log('Warning: S3 Transfer Acceleration will not be enabled on deploymentBucket.');
log.warning('S3 Transfer Acceleration cannot be enabled on user provided S3 bucket');
this.serverless._logDeprecation(
'S3_TRANSFER_ACCELERATION_ON_EXISTING_BUCKET',
'Starting with "v3.0.0", attempt to enable S3 Transfer Acceleration on user provided bucket will result in error instead of a warning. To ensure seamless upgrade, please stop using "--aws-s3-accelerate" flag.'
);
}
this.bucketName = bucketName;
this.serverless.service.package.deploymentBucket = bucketName;
Expand Down
37 changes: 18 additions & 19 deletions test/unit/lib/plugins/aws/package/lib/generateCoreTemplate.test.js
Expand Up @@ -152,28 +152,27 @@ describe('#generateCoreTemplate()', () => {
});
}));

it('should use a custom bucket if specified, even with S3 transfer acceleration', () => {
it('should result in deprecation error for custom bucket and accelerate flag', async () => {
const bucketName = 'com.serverless.deploys';

return runServerless({
config: {
service: 'irrelevant',
provider: {
name: 'aws',
deploymentBucket: bucketName,
await expect(
runServerless({
config: {
service: 'irrelevant',
provider: {
name: 'aws',
deploymentBucket: bucketName,
},
},
},
command: 'deploy',
options: { 'aws-s3-accelerate': true },
lastLifecycleHookName: 'before:deploy:deploy',
awsRequestStubMap: { S3: { getBucketLocation: { LocationConstraint: '' } } },
}).then(({ cfTemplate: template }) => {
expect(template.Outputs.ServerlessDeploymentBucketName.Value).to.equal(bucketName);
// eslint-disable-next-line no-unused-expressions
expect(template.Resources.ServerlessDeploymentBucket).to.not.exist;
// eslint-disable-next-line no-unused-expressions
expect(template.Outputs.ServerlessDeploymentBucketAccelerated).to.not.exist;
});
command: 'deploy',
options: { 'aws-s3-accelerate': true },
lastLifecycleHookName: 'before:deploy:deploy',
awsRequestStubMap: { S3: { getBucketLocation: { LocationConstraint: '' } } },
})
).to.eventually.be.rejected.and.have.property(
'code',
'REJECTED_DEPRECATION_S3_TRANSFER_ACCELERATION_ON_EXISTING_BUCKET'
);
});

it('should use a auto generated bucket if you does not specify deploymentBucket', () =>
Expand Down

0 comments on commit 04b921a

Please sign in to comment.