Skip to content

Migrate to HTTP APIs #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: push
on: [push, pull_request]

jobs:
build:
Expand All @@ -16,12 +16,12 @@ jobs:

- name: yamlllint
run: |
pip install yamllint==1.24.2
pip install yamllint==1.25.0
yamllint module.yml && yamllint test/*.yml

- name: cfn-lint
run: |
pip install cfn-lint==0.34.0
pip install cfn-lint==0.39.0
cfn-lint -t module.yml && cfn-lint -t test/*.yml

- name: license
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion lambda-src/README.md

This file was deleted.

36 changes: 0 additions & 36 deletions lambda-src/custom-resource-deployment.js

This file was deleted.

11 changes: 0 additions & 11 deletions lambda-src/node_modules/cfn-response/README.md

This file was deleted.

54 changes: 0 additions & 54 deletions lambda-src/node_modules/cfn-response/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions lambda-src/node_modules/cfn-response/license.txt

This file was deleted.

58 changes: 0 additions & 58 deletions lambda-src/node_modules/cfn-response/package.json

This file was deleted.

11 changes: 0 additions & 11 deletions lambda-src/package-lock.json

This file was deleted.

6 changes: 0 additions & 6 deletions lambda-src/package.json

This file was deleted.

80 changes: 15 additions & 65 deletions module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ Parameters:
Description: 'Optional but recommended stack name of alerting module.'
Type: String
Default: ''
HttpMethod:
Description: 'The HTTP method that clients use to call this method.'
Type: String
Default: ANY
AllowedValues: [ANY, GET, HEAD, POST, PUT, DELETE, OPTIONS]
Conditions:
HasAlertingModule: !Not [!Equals [!Ref AlertingModule, '']]
Resources:
Expand All @@ -37,49 +32,24 @@ Resources:
Action: 'lambda:InvokeFunction'
FunctionName: {'Fn::ImportValue': !Sub '${LambdaModule}-Name'}
Principal: 'apigateway.amazonaws.com'
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/${HttpMethod}/'
RestApi:
Type: 'AWS::ApiGateway::RestApi'
SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${Api}/*/$default'
Api:
Type: 'AWS::ApiGatewayV2::Api'
Properties:
Name: !Ref 'AWS::StackName'
Stage:
Type: 'AWS::ApiGateway::Stage'
Properties:
DeploymentId: !Ref DeploymentCustom
RestApiId: !Ref RestApi
StageName: webhook
DeploymentCustom:
DependsOn: Method
Type: 'Custom::Deployment'
Version: '1.0'
Properties:
LambdaModule: !Ref LambdaModule
HttpMethod: !Ref HttpMethod
RestApiId: !Ref RestApi
ServiceToken: !GetAtt 'DeploymentFunction.Outputs.Arn'
Method:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
HttpMethod: !Ref HttpMethod
Integration:
IntegrationHttpMethod: 'POST'
PassthroughBehavior: 'WHEN_NO_MATCH'
Type: 'AWS_PROXY'
Uri: !Sub
- 'arn:${Partition}:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations'
- Partition: !Ref 'AWS::Partition'
Region: !Ref 'AWS::Region'
LambdaFunctionArn: {'Fn::ImportValue': !Sub '${LambdaModule}-Arn'}
ResourceId: !GetAtt 'RestApi.RootResourceId'
RestApiId: !Ref RestApi
ProtocolType: HTTP
Target: !Sub
- 'arn:${Partition}:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations'
- Partition: !Ref 'AWS::Partition'
Region: !Ref 'AWS::Region'
LambdaFunctionArn: {'Fn::ImportValue': !Sub '${LambdaModule}-Arn'}
Alarm5XXErrorTooHigh:
Condition: HasAlertingModule
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmDescription: 'Api Gateway server-side errors captured'
Namespace: 'AWS/ApiGateway'
MetricName: 5XXError
MetricName: 5xx
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Expand All @@ -88,39 +58,19 @@ Resources:
AlarmActions:
- 'Fn::ImportValue': !Sub '${AlertingModule}-Arn'
Dimensions:
- Name: ApiName
Value: !Ref 'AWS::StackName'
- Name: ApiId
Value: !Ref Api
- Name: Stage
Value: !Ref Stage
Value: '$default'
TreatMissingData: notBreaching
DeploymentFunctionPolicy:
Type: 'AWS::IAM::ManagedPolicy'
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'apigateway:POST'
- 'apigateway:DELETE'
Resource: !Sub 'arn:${AWS::Partition}:apigateway:${AWS::Region}::/restapis/${RestApi}/*'
DeploymentFunction:
Type: 'AWS::CloudFormation::Stack'
Properties:
Parameters:
Handler: 'custom-resource-deployment.handler'
Runtime: 'nodejs10.x'
Timeout: '30'
ManagedPolicyArns: !Ref DeploymentFunctionPolicy
TemplateURL: './node_modules/@cfn-modules/lambda-function/module.yml'
Outputs:
ModuleId:
Value: 'lambda-event-source-webhook'
ModuleVersion:
Value: '1.2.1'
Value: '2.0.0'
StackName:
Value: !Ref 'AWS::StackName'
Url:
Value: !Sub 'https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}'
Value: !GetAtt 'Api.ApiEndpoint'
Export:
Name: !Sub '${AWS::StackName}-Url'
1 change: 0 additions & 1 deletion node_modules/@cfn-modules/lambda-function
Submodule lambda-function deleted from d992e9
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "@cfn-modules/lambda-event-source-webhook",
"version": "1.2.1",
"version": "2.0.0",
"description": "Webhook event source for AWS Lambda function",
"author": "Michael Wittig <michael@widdix.de>",
"license": "Apache-2.0",
"bundledDependencies": ["@cfn-modules/lambda-function"],
"keywords": ["cfn-modules"],
"homepage": "https://github.com/cfn-modules",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion test/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Resources:
Properties:
Parameters:
Handler: 'defaults.handler'
Runtime: 'nodejs10.x'
Runtime: 'nodejs12.x'
TemplateURL: './node_modules/@cfn-modules/lambda-function/module.yml'
Outputs:
Url:
Expand Down
Loading