diff --git a/lib/shortcuts/hookshot.js b/lib/shortcuts/hookshot.js index 5f2e36b..1fe8cb9 100644 --- a/lib/shortcuts/hookshot.js +++ b/lib/shortcuts/hookshot.js @@ -100,88 +100,88 @@ class Passthrough { this.Prefix = Prefix; this.PassthroughTo = PassthroughTo; - const Resources = { - [`${Prefix}Secret`]: { - Type: 'AWS::ApiGateway::ApiKey', - Properties: { - Enabled: false - } - }, + const Resources = {}; + Resources[`${Prefix}Secret`] = { + Type: 'AWS::ApiGateway::ApiKey', + Properties: { + Enabled: false + } + }; - [`${Prefix}Api`]: { - Type: 'AWS::ApiGateway::RestApi', - Properties: { - Name: { 'Fn::Sub': '${AWS::StackName}-webhook' }, - FailOnWarnings: true - } - }, + Resources[`${Prefix}Api`] = { + Type: 'AWS::ApiGateway::RestApi', + Properties: { + Name: { 'Fn::Sub': '${AWS::StackName}-webhook' }, + FailOnWarnings: true + } + }; - [`${Prefix}Stage`]: { - Type: 'AWS::ApiGateway::Stage', - Properties: { - DeploymentId: { Ref: `${Prefix}Deployment${random}` }, - StageName: 'hookshot', - RestApiId: { Ref: `${Prefix}Api` }, - MethodSettings: [ - { - HttpMethod: '*', - ResourcePath: '/*', - ThrottlingBurstLimit: 20, - ThrottlingRateLimit: 5, - LoggingLevel, - DataTraceEnabled, - MetricsEnabled - } - ] - } - }, + Resources[`${Prefix}Stage`] = { + Type: 'AWS::ApiGateway::Stage', + Properties: { + DeploymentId: { Ref: `${Prefix}Deployment${random}` }, + StageName: 'hookshot', + RestApiId: { Ref: `${Prefix}Api` }, + MethodSettings: [ + { + HttpMethod: '*', + ResourcePath: '/*', + ThrottlingBurstLimit: 20, + ThrottlingRateLimit: 5, + LoggingLevel, + DataTraceEnabled, + MetricsEnabled + } + ] + } + }; - [`${Prefix}Deployment${random}`]: { - Type: 'AWS::ApiGateway::Deployment', - DependsOn: `${Prefix}Method`, - Properties: { - RestApiId: { Ref: `${Prefix}Api` }, - StageName: 'unused' - } - }, + Resources[`${Prefix}Deployment${random}`] = { + Type: 'AWS::ApiGateway::Deployment', + DependsOn: `${Prefix}Method`, + Properties: { + RestApiId: { Ref: `${Prefix}Api` }, + StageName: 'unused' + } + }; - [`${Prefix}Resource`]: { - Type: 'AWS::ApiGateway::Resource', - Properties: { - ParentId: { 'Fn::GetAtt': [`${Prefix}Api`, 'RootResourceId'] }, - RestApiId: { Ref: `${Prefix}Api` }, - PathPart: 'webhook' - } - }, + Resources[`${Prefix}Resource`] = { + Type: 'AWS::ApiGateway::Resource', + Properties: { + ParentId: { 'Fn::GetAtt': [`${Prefix}Api`, 'RootResourceId'] }, + RestApiId: { Ref: `${Prefix}Api` }, + PathPart: 'webhook' + } + }; - [`${Prefix}OptionsMethod`]: { - Type: 'AWS::ApiGateway::Method', - Properties: { - RestApiId: { Ref: `${Prefix}Api` }, - ResourceId: { Ref: `${Prefix}Resource` }, - ApiKeyRequired: false, - AuthorizationType: 'None', - HttpMethod: 'OPTIONS', - Integration: { - Type: 'AWS_PROXY', - IntegrationHttpMethod: 'POST', - Uri: { 'Fn::Sub': `arn:aws:apigateway:\${AWS::Region}:lambda:path/2015-03-31/functions/\${${Prefix}Function.Arn}/invocations` } - } + Resources[`${Prefix}OptionsMethod`] = { + Type: 'AWS::ApiGateway::Method', + Properties: { + RestApiId: { Ref: `${Prefix}Api` }, + ResourceId: { Ref: `${Prefix}Resource` }, + ApiKeyRequired: false, + AuthorizationType: 'None', + HttpMethod: 'OPTIONS', + Integration: { + Type: 'AWS_PROXY', + IntegrationHttpMethod: 'POST', + Uri: { 'Fn::Sub': `arn:aws:apigateway:\${AWS::Region}:lambda:path/2015-03-31/functions/\${${Prefix}Function.Arn}/invocations` } } - }, + } + }; - [`${Prefix}Method`]: this.method(), + Resources[`${Prefix}Method`] = this.method(), - [`${Prefix}Permission`]: { - Type: 'AWS::Lambda::Permission', - Properties: { - FunctionName: { Ref: `${Prefix}Function` }, - Action: 'lambda:InvokeFunction', - Principal: 'apigateway.amazonaws.com', - SourceArn: { 'Fn::Sub': `arn:aws:execute-api:\${AWS::Region}:\${AWS::AccountId}:\${${Prefix}Api}/*` } - } + Resources[`${Prefix}Permission`] = { + Type: 'AWS::Lambda::Permission', + Properties: { + FunctionName: { Ref: `${Prefix}Function` }, + Action: 'lambda:InvokeFunction', + Principal: 'apigateway.amazonaws.com', + SourceArn: { 'Fn::Sub': `arn:aws:execute-api:\${AWS::Region}:\${AWS::AccountId}:\${${Prefix}Api}/*` } } }; + if (AccessLogFormat) { Resources[`${Prefix}AccessLogs`] = { diff --git a/lib/shortcuts/lambda.js b/lib/shortcuts/lambda.js index 45ed274..1599249 100644 --- a/lib/shortcuts/lambda.js +++ b/lib/shortcuts/lambda.js @@ -107,102 +107,101 @@ class Lambda { this.LogicalName = LogicalName; this.FunctionName = FunctionName; this.Condition = Condition; + this.Resources = {}; - this.Resources = { - [`${LogicalName}Logs`]: { - Type: 'AWS::Logs::LogGroup', - Condition, - Properties: { - LogGroupName: { - 'Fn::Sub': ['/aws/lambda/${name}', { name: FunctionName }] - }, - RetentionInDays: 14 - } - }, + this.Resources[`${LogicalName}Logs`] = { + Type: 'AWS::Logs::LogGroup', + Condition, + Properties: { + LogGroupName: { + 'Fn::Sub': ['/aws/lambda/${name}', { name: FunctionName }] + }, + RetentionInDays: 14 + } + }; - [`${LogicalName}Role`]: { - Type: 'AWS::IAM::Role', - Condition, - Properties: { - AssumeRolePolicyDocument: { - Statement: [ - { - Effect: 'Allow', - Action: 'sts:AssumeRole', - Principal: { - Service: 'lambda.amazonaws.com' - } - } - ] - }, - Policies: [ + this.Resources[`${LogicalName}Role`] = { + Type: 'AWS::IAM::Role', + Condition, + Properties: { + AssumeRolePolicyDocument: { + Statement: [ { - PolicyName: 'main', - PolicyDocument: { - Statement: [ - { - Effect: 'Allow', - Action: 'logs:*', - Resource: { - 'Fn::GetAtt': [`${LogicalName}Logs`, 'Arn'] - } - }, - ...Statement - ] + Effect: 'Allow', + Action: 'sts:AssumeRole', + Principal: { + Service: 'lambda.amazonaws.com' } } ] - } - }, + }, + Policies: [ + { + PolicyName: 'main', + PolicyDocument: { + Statement: [ + { + Effect: 'Allow', + Action: 'logs:*', + Resource: { + 'Fn::GetAtt': [`${LogicalName}Logs`, 'Arn'] + } + }, + ...Statement + ] + } + } + ] + } + }; - [`${LogicalName}`]: { - Type: 'AWS::Lambda::Function', - Condition, - DependsOn, - Properties: { - Code, - DeadLetterConfig, - Description, - Environment, - FunctionName, - Handler, - KmsKeyArn, - MemorySize, - ReservedConcurrentExecutions, - Role: { 'Fn::GetAtt': [`${LogicalName}Role`, 'Arn'] }, - Runtime, - Timeout, - TracingConfig, - VpcConfig, - Tags - } - }, + this.Resources[`${LogicalName}`] = { + Type: 'AWS::Lambda::Function', + Condition, + DependsOn, + Properties: { + Code, + DeadLetterConfig, + Description, + Environment, + FunctionName, + Handler, + KmsKeyArn, + MemorySize, + ReservedConcurrentExecutions, + Role: { 'Fn::GetAtt': [`${LogicalName}Role`, 'Arn'] }, + Runtime, + Timeout, + TracingConfig, + VpcConfig, + Tags + } + }; - [`${LogicalName}ErrorAlarm`]: { - Type: 'AWS::CloudWatch::Alarm', - Condition, - Properties: { - AlarmName, - AlarmDescription, - AlarmActions, - Period, - EvaluationPeriods, - Statistic, - Threshold, - ComparisonOperator, - TreatMissingData, - EvaluateLowSampleCountPercentile, - ExtendedStatistic, - OKActions, - Namespace: 'AWS/Lambda', - Dimensions: [ - { - Name: 'FunctionName', - Value: { 'Ref': LogicalName } - } - ], - MetricName: 'Errors' - } + this.Resources[`${LogicalName}ErrorAlarm`] = { + Type: 'AWS::CloudWatch::Alarm', + Condition, + Properties: { + AlarmName, + AlarmDescription, + AlarmActions, + Period, + EvaluationPeriods, + Statistic, + Threshold, + ComparisonOperator, + TreatMissingData, + EvaluateLowSampleCountPercentile, + ExtendedStatistic, + OKActions, + Namespace: 'AWS/Lambda', + Dimensions: [ + { + Name: 'FunctionName', + Value: { 'Ref': LogicalName } + } + ], + MetricName: 'Errors' } }; }