Skip to content

Commit

Permalink
fix remaining tsc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jseppi committed Mar 4, 2019
1 parent b8207a3 commit 8e79f55
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 160 deletions.
144 changes: 72 additions & 72 deletions lib/shortcuts/hookshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = {
Expand Down
175 changes: 87 additions & 88 deletions lib/shortcuts/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
};
}
Expand Down

0 comments on commit 8e79f55

Please sign in to comment.