serverless-step-functions
Version:
The module is AWS Step Functions plugin for Serverless Framework
44 lines (37 loc) • 1.29 kB
JavaScript
;
const _ = require('lodash');
const BbPromise = require('bluebird');
module.exports = {
compileApiKeys() {
const apiKeys = _.get(this.serverless.service.provider.apiGateway, 'apiKeys')
|| this.serverless.service.provider.apiKeys;
if (apiKeys) {
if (!Array.isArray(apiKeys)) {
throw new this.serverless.classes.Error('apiKeys property must be an array');
}
_.forEach(apiKeys, (apiKey, i) => {
const apiKeyNumber = i + 1;
if (typeof apiKey !== 'string') {
throw new this.serverless.classes.Error('API Keys must be strings');
}
const apiKeyLogicalId = this.provider.naming
.getApiKeyLogicalId(apiKeyNumber);
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, {
[apiKeyLogicalId]: {
Type: 'AWS::ApiGateway::ApiKey',
Properties: {
Enabled: true,
Name: apiKey,
StageKeys: [{
RestApiId: { Ref: this.apiGatewayRestApiLogicalId },
StageName: this.provider.getStage(),
}],
},
DependsOn: this.apiGatewayDeploymentLogicalId,
},
});
});
}
return BbPromise.resolve();
},
};