Skip to content

Commit 86e87e0

Browse files
Migrate to HTTP APIs (#13)
1 parent c380895 commit 86e87e0

File tree

16 files changed

+168
-389
lines changed

16 files changed

+168
-389
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: push
3+
on: [push, pull_request]
44

55
jobs:
66
build:
@@ -16,12 +16,12 @@ jobs:
1616

1717
- name: yamlllint
1818
run: |
19-
pip install yamllint==1.24.2
19+
pip install yamllint==1.25.0
2020
yamllint module.yml && yamllint test/*.yml
2121
2222
- name: cfn-lint
2323
run: |
24-
pip install cfn-lint==0.34.0
24+
pip install cfn-lint==0.39.0
2525
cfn-lint -t module.yml && cfn-lint -t test/*.yml
2626
2727
- name: license

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

lambda-src/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

lambda-src/custom-resource-deployment.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

lambda-src/node_modules/cfn-response/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

lambda-src/node_modules/cfn-response/index.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

lambda-src/node_modules/cfn-response/license.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

lambda-src/node_modules/cfn-response/package.json

Lines changed: 0 additions & 58 deletions
This file was deleted.

lambda-src/package-lock.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

lambda-src/package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

module.yml

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ Parameters:
2323
Description: 'Optional but recommended stack name of alerting module.'
2424
Type: String
2525
Default: ''
26-
HttpMethod:
27-
Description: 'The HTTP method that clients use to call this method.'
28-
Type: String
29-
Default: ANY
30-
AllowedValues: [ANY, GET, HEAD, POST, PUT, DELETE, OPTIONS]
3126
Conditions:
3227
HasAlertingModule: !Not [!Equals [!Ref AlertingModule, '']]
3328
Resources:
@@ -37,49 +32,24 @@ Resources:
3732
Action: 'lambda:InvokeFunction'
3833
FunctionName: {'Fn::ImportValue': !Sub '${LambdaModule}-Name'}
3934
Principal: 'apigateway.amazonaws.com'
40-
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/${HttpMethod}/'
41-
RestApi:
42-
Type: 'AWS::ApiGateway::RestApi'
35+
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${Api}/*/$default'
36+
Api:
37+
Type: 'AWS::ApiGatewayV2::Api'
4338
Properties:
4439
Name: !Ref 'AWS::StackName'
45-
Stage:
46-
Type: 'AWS::ApiGateway::Stage'
47-
Properties:
48-
DeploymentId: !Ref DeploymentCustom
49-
RestApiId: !Ref RestApi
50-
StageName: webhook
51-
DeploymentCustom:
52-
DependsOn: Method
53-
Type: 'Custom::Deployment'
54-
Version: '1.0'
55-
Properties:
56-
LambdaModule: !Ref LambdaModule
57-
HttpMethod: !Ref HttpMethod
58-
RestApiId: !Ref RestApi
59-
ServiceToken: !GetAtt 'DeploymentFunction.Outputs.Arn'
60-
Method:
61-
Type: 'AWS::ApiGateway::Method'
62-
Properties:
63-
AuthorizationType: NONE
64-
HttpMethod: !Ref HttpMethod
65-
Integration:
66-
IntegrationHttpMethod: 'POST'
67-
PassthroughBehavior: 'WHEN_NO_MATCH'
68-
Type: 'AWS_PROXY'
69-
Uri: !Sub
70-
- 'arn:${Partition}:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations'
71-
- Partition: !Ref 'AWS::Partition'
72-
Region: !Ref 'AWS::Region'
73-
LambdaFunctionArn: {'Fn::ImportValue': !Sub '${LambdaModule}-Arn'}
74-
ResourceId: !GetAtt 'RestApi.RootResourceId'
75-
RestApiId: !Ref RestApi
40+
ProtocolType: HTTP
41+
Target: !Sub
42+
- 'arn:${Partition}:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations'
43+
- Partition: !Ref 'AWS::Partition'
44+
Region: !Ref 'AWS::Region'
45+
LambdaFunctionArn: {'Fn::ImportValue': !Sub '${LambdaModule}-Arn'}
7646
Alarm5XXErrorTooHigh:
7747
Condition: HasAlertingModule
7848
Type: 'AWS::CloudWatch::Alarm'
7949
Properties:
8050
AlarmDescription: 'Api Gateway server-side errors captured'
8151
Namespace: 'AWS/ApiGateway'
82-
MetricName: 5XXError
52+
MetricName: 5xx
8353
Statistic: Sum
8454
Period: 60
8555
EvaluationPeriods: 1
@@ -88,39 +58,19 @@ Resources:
8858
AlarmActions:
8959
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
9060
Dimensions:
91-
- Name: ApiName
92-
Value: !Ref 'AWS::StackName'
61+
- Name: ApiId
62+
Value: !Ref Api
9363
- Name: Stage
94-
Value: !Ref Stage
64+
Value: '$default'
9565
TreatMissingData: notBreaching
96-
DeploymentFunctionPolicy:
97-
Type: 'AWS::IAM::ManagedPolicy'
98-
Properties:
99-
PolicyDocument:
100-
Version: '2012-10-17'
101-
Statement:
102-
- Effect: Allow
103-
Action:
104-
- 'apigateway:POST'
105-
- 'apigateway:DELETE'
106-
Resource: !Sub 'arn:${AWS::Partition}:apigateway:${AWS::Region}::/restapis/${RestApi}/*'
107-
DeploymentFunction:
108-
Type: 'AWS::CloudFormation::Stack'
109-
Properties:
110-
Parameters:
111-
Handler: 'custom-resource-deployment.handler'
112-
Runtime: 'nodejs10.x'
113-
Timeout: '30'
114-
ManagedPolicyArns: !Ref DeploymentFunctionPolicy
115-
TemplateURL: './node_modules/@cfn-modules/lambda-function/module.yml'
11666
Outputs:
11767
ModuleId:
11868
Value: 'lambda-event-source-webhook'
11969
ModuleVersion:
120-
Value: '1.2.1'
70+
Value: '2.0.0'
12171
StackName:
12272
Value: !Ref 'AWS::StackName'
12373
Url:
124-
Value: !Sub 'https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}'
74+
Value: !GetAtt 'Api.ApiEndpoint'
12575
Export:
12676
Name: !Sub '${AWS::StackName}-Url'
Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"name": "@cfn-modules/lambda-event-source-webhook",
3-
"version": "1.2.1",
3+
"version": "2.0.0",
44
"description": "Webhook event source for AWS Lambda function",
55
"author": "Michael Wittig <michael@widdix.de>",
66
"license": "Apache-2.0",
7-
"bundledDependencies": ["@cfn-modules/lambda-function"],
87
"keywords": ["cfn-modules"],
98
"homepage": "https://github.com/cfn-modules",
109
"bugs": {

test/defaults.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Resources:
1313
Properties:
1414
Parameters:
1515
Handler: 'defaults.handler'
16-
Runtime: 'nodejs10.x'
16+
Runtime: 'nodejs12.x'
1717
TemplateURL: './node_modules/@cfn-modules/lambda-function/module.yml'
1818
Outputs:
1919
Url:

0 commit comments

Comments
 (0)