Skip to content

Commit 3213854

Browse files
authored
Support S3 server side encryption (#65)
* Added support for CFN role. * Support S3 server side encryption * Added unit test for updateAlias. Fixed alias tag in create fallback. * Added tests for uploadAliasArtifacts
1 parent 2ae1e4c commit 3213854

File tree

4 files changed

+552
-2
lines changed

4 files changed

+552
-2
lines changed

lib/updateAliasStack.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
this._serverless.cli.log('Creating alias stack...');
1414

1515
const stackName = `${this._provider.naming.getStackName()}-${this._alias}`;
16-
let stackTags = { STAGE: this._options.stage };
16+
let stackTags = { STAGE: this._options.stage, ALIAS: this._alias };
1717
const templateUrl = `https://s3.amazonaws.com/${
1818
this.bucketName
1919
}/${
@@ -36,6 +36,10 @@ module.exports = {
3636
Tags: _.map(_.keys(stackTags), key => ({ Key: key, Value: stackTags[key] })),
3737
};
3838

39+
if (this.serverless.service.provider.cfnRole) {
40+
params.RoleARN = this.serverless.service.provider.cfnRole;
41+
}
42+
3943
return this._provider.request('CloudFormation',
4044
'createStack',
4145
params,
@@ -71,6 +75,10 @@ module.exports = {
7175
Tags: _.map(_.keys(stackTags), key => ({ Key: key, Value: stackTags[key] })),
7276
};
7377

78+
if (this.serverless.service.provider.cfnRole) {
79+
params.RoleARN = this.serverless.service.provider.cfnRole;
80+
}
81+
7482
// Policy must have at least one statement, otherwise no updates would be possible at all
7583
if (this._serverless.service.provider.stackPolicy &&
7684
this._serverless.service.provider.stackPolicy.length) {

lib/uploadAliasArtifacts.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const BbPromise = require('bluebird');
4+
const _ = require('lodash');
45

56
module.exports = {
67
uploadAliasCloudFormationFile() {
@@ -10,13 +11,18 @@ module.exports = {
1011

1112
const fileName = 'compiled-cloudformation-template-alias.json';
1213

13-
const params = {
14+
let params = {
1415
Bucket: this.bucketName,
1516
Key: `${this.serverless.service.package.artifactDirectoryName}/${fileName}`,
1617
Body: body,
1718
ContentType: 'application/json',
1819
};
1920

21+
const deploymentBucketObject = this.serverless.service.provider.deploymentBucketObject;
22+
if (deploymentBucketObject) {
23+
params = setServersideEncryptionOptions(params, deploymentBucketObject);
24+
}
25+
2026
return this.provider.request('S3',
2127
'putObject',
2228
params,
@@ -34,3 +40,23 @@ module.exports = {
3440
},
3541

3642
};
43+
44+
function setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
45+
const encryptionFields = {
46+
'serverSideEncryption': 'ServerSideEncryption',
47+
'sseCustomerAlgorithm': 'SSECustomerAlgorithm',
48+
'sseCustomerKey': 'SSECustomerKey',
49+
'sseCustomerKeyMD5': 'SSECustomerKeyMD5',
50+
'sseKMSKeyId': 'SSEKMSKeyId',
51+
};
52+
53+
const params = putParams;
54+
55+
_.forOwn(encryptionFields, (value, field) => {
56+
if (deploymentBucketOptions[field]) {
57+
params[value] = deploymentBucketOptions[field];
58+
}
59+
});
60+
61+
return params;
62+
}

0 commit comments

Comments
 (0)