This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
73 lines (72 loc) · 2.35 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Transform: AWS::Serverless-2016-10-31
Parameters:
EventBusName:
Type: String
Default: StripeEventBus
Description: (Required) Name of EventBus.
StripeWebhookSecret:
Type: String
Default: wshec_1234
Description: (Required) Your Stripe webhooks secret
StripeSecretKey:
Type: String
Default: sk_12345
Description: (Required) Your Stripe secret key
Resources:
# A Lambda function to receive events from Stripe
EventReciever:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs12.x
Handler: send-to-event-bus.handler
CodeUri: ./lib
Environment:
Variables:
EVENT_BUS_NAME: !Ref EventBusName
STRIPE_WEBHOOK_SECRET: !Ref StripeWebhookSecret
STRIPE_SECRET_KEY: !Ref StripeSecretKey
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- events:PutEvents
Resource: '*'
Events:
WebhookEndpoint:
# Define an API Gateway endpoint that responds to HTTP GET at /thumbnail
Type: Api
Properties:
Path: /webhook
Method: POST
# An Event Bus for EventReciever to send events to
EventBus:
Type: AWS::Events::EventBus
Properties:
Name: StripeEventBus # Make sure this is the same value as the EventBus defined as EVENT_BUS_NAME
# A Lambda function to process specific events from Stripe
EventProcessor:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs12.x
Handler: event-processor.handler
CodeUri: ./lib
# An Event Rule to listen for payment_intent.succeeded Stripe event and route it to EventProcessor function
EventListener:
Type: AWS::Events::Rule
Properties:
Description: Handles Stripe events
EventBusName: !GetAtt EventBus.Name
EventPattern: { "source": [ "Stripe" ], "detail-type": [ "payment_intent.succeeded" ] }
Targets:
-
Id: something
Arn: !GetAtt EventProcessor.Arn
# Permission to allow EventListener to send events to EventProcessor
EventProcessorPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt EventProcessor.Arn
Principal: events.amazonaws.com
SourceArn: !GetAtt EventListener.Arn