mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const path = require('path');
|
|
const BbPromise = require('bluebird');
|
|
|
|
module.exports = {
|
|
initializeResources() {
|
|
const coreCFTemplate = this.serverless.utils.readFileSync(
|
|
path.join(this.serverless.config.serverlessPath,
|
|
'plugins',
|
|
'aws',
|
|
'deploy',
|
|
'lib',
|
|
'core-cf.json')
|
|
);
|
|
|
|
// set the necessary variables before creating stack
|
|
coreCFTemplate
|
|
.Resources
|
|
.IamPolicyLambda
|
|
.Properties
|
|
.PolicyName = `${this.options.stage}-${this.serverless.service.service}-lambda`;
|
|
coreCFTemplate
|
|
.Resources
|
|
.IamPolicyLambda
|
|
.Properties
|
|
.PolicyDocument
|
|
.Statement[0]
|
|
.Resource = `arn:aws:logs:${this.options.region}:*:*`;
|
|
|
|
// add custom iam role statements
|
|
if (this.serverless.service.provider.iamRoleStatements &&
|
|
this.serverless.service.provider.iamRoleStatements instanceof Array) {
|
|
coreCFTemplate
|
|
.Resources
|
|
.IamPolicyLambda
|
|
.Properties
|
|
.PolicyDocument
|
|
.Statement = coreCFTemplate
|
|
.Resources
|
|
.IamPolicyLambda
|
|
.Properties
|
|
.PolicyDocument
|
|
.Statement.concat(this.serverless.service.provider.iamRoleStatements);
|
|
}
|
|
|
|
// check if the user has added some "custom Resources" (and merge them into coreCFTemplate)
|
|
if (this.serverless.service.resources && this.serverless.service.resources.Resources) {
|
|
_.forEach(this.serverless.service.resources.Resources, (value, key) => {
|
|
const newResourceObject = {
|
|
[key]: value,
|
|
};
|
|
|
|
_.merge(coreCFTemplate.Resources, newResourceObject);
|
|
});
|
|
}
|
|
|
|
this.serverless.service.resources = coreCFTemplate;
|
|
|
|
return BbPromise.resolve();
|
|
},
|
|
};
|