-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudformation2-sns-lambda-gateway.yaml
80 lines (70 loc) · 2.47 KB
/
cloudformation2-sns-lambda-gateway.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
74
75
76
77
78
79
80
AWSTemplateFormatVersion: '2010-09-09'
Description: Create Lambda function, API Gateway, and SNS topic for topic subscription
Parameters:
LambdaExecutionRole:
Type: String
Description: IAM role ARN for Lambda execution
Default: "arn:aws:iam::426085379010:role/LabRole"
Resources:
EmailSubscriptionLambda:
Type: 'AWS::Lambda::Function'
Properties:
Handler: lambda/index.handler
Role: !Ref LambdaExecutionRole
Code:
S3Bucket: lambdamerin1
S3Key: lambda.zip
Runtime: nodejs18.x
EmailSubscriptionApiGateway:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: EmailSubscriptionApi
EmailSubscriptionResource:
Type: 'AWS::ApiGateway::Resource'
Properties:
RestApiId: !Ref EmailSubscriptionApiGateway
ParentId: !GetAtt EmailSubscriptionApiGateway.RootResourceId
PathPart: 'lambda'
EmailSubscriptionMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
RestApiId: !Ref EmailSubscriptionApiGateway
ResourceId: !Ref EmailSubscriptionResource
HttpMethod: 'POST'
AuthorizationType: 'NONE'
Integration:
Type: 'AWS_PROXY'
IntegrationHttpMethod: 'POST'
Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EmailSubscriptionLambda.Arn}/invocations'
MethodResponses:
- StatusCode: 200
ResponseModels:
'application/json': 'Empty'
OperationName: 'SubscribeEmail'
RequestModels:
'application/json': 'Empty'
EmailSubscriptionPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !GetAtt EmailSubscriptionLambda.Arn
Principal: 'apigateway.amazonaws.com'
SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${EmailSubscriptionApiGateway}/*/*/*'
EmailSubscriptionSnsTopic:
Type: 'AWS::SNS::Topic'
Properties:
DisplayName: 'Email Notification'
TopicName: 'DailyNotification'
ApiGatewayDeployment:
Type: 'AWS::ApiGateway::Deployment'
DependsOn: EmailSubscriptionMethod
Properties:
RestApiId: !Ref EmailSubscriptionApiGateway
StageName: 'prod'
Outputs:
ApiGatewayInvokeUrl:
Description: 'URL to invoke the API Gateway endpoint'
Value: !Sub 'https://${EmailSubscriptionApiGateway}.execute-api.${AWS::Region}.amazonaws.com/lambda/'
SnsTopicArn:
Description: 'ARN of the created SNS topic'
Value: !Ref EmailSubscriptionSnsTopic