-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
148 lines (136 loc) · 3.99 KB
/
Copy pathtemplate.yaml
File metadata and controls
148 lines (136 loc) · 3.99 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
AWSTemplateFormatVersion: 2010-09-09
Description: REST API
Parameters:
LambdaFunctionName:
Type: String
Default: tradingNews-lambda
PackageBucketName:
Type: String
Default: oncobe-cf-packages
TradingFunctionPackage:
Type: String
TradingAPIURL:
Type: String
Default: https://trading-view.p.rapidapi.com/news/list
TradingAPIKey:
Type: String
Default: 3fb2350dd0msh962751bd232e22ep141805jsnd4607e8a45ef
Env:
Type: String
Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: !Ref PackageBucketName
S3Key: !Ref TradingFunctionPackage
Runtime: python3.10
Description: lambda function to retrieve latest trading news
FunctionName: !Sub ${LambdaFunctionName}-${Env}
Handler: tradingNewsLambda.lambda_handler
MemorySize: 256
Role: !GetAtt LambdaIAMRole.Arn
Timeout: 30
Environment:
Variables:
TRADING_NEWS_API_URL: !Ref TradingAPIURL
TRADING_NEWS_API_KEY: !Ref TradingAPIKey
LambdaIAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Policies:
- PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${LambdaFunctionName}-${Env}:*
PolicyName: lambda
ApiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
Name: REST API gateway
Description: RESTFULL API
EndpointConfiguration:
Types:
- EDGE
ApiKeySourceType: HEADER
ApiGatewayResourceNews:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt ApiGateway.RootResourceId
PathPart: trading-news
RestApiId: !Ref ApiGateway
ApiGatewayGETMethod:
Type: AWS::ApiGateway::Method
Properties:
ApiKeyRequired: false
AuthorizationType: NONE
HttpMethod: GET
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaArn}/invocations
- LambdaArn: !GetAtt LambdaFunction.Arn
ResourceId: !Ref ApiGatewayResourceNews
RestApiId: !Ref ApiGateway
ApiGatewayStage:
Type: AWS::ApiGateway::Stage
Properties:
DeploymentId: !Ref ApiGatewayDeployment
MethodSettings:
- HttpMethod: '*'
LoggingLevel: INFO
ResourcePath: /*
DataTraceEnabled: true
Description: Mock API Stage v0
RestApiId: !Ref ApiGateway
StageName: 'v0'
ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn: ApiGatewayGETMethod
Properties:
Description: Mock API Deployment
RestApiId: !Ref ApiGateway
LambdaApiGatewayInvoke:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt LambdaFunction.Arn
Principal: apigateway.amazonaws.com
ApiGatewayRoleArn:
Type: AWS::ApiGateway::Account
Properties:
CloudWatchRoleArn: !GetAtt CloudWatchRole.Arn
# IAM Role for API Gateway + CloudWatch Logging
CloudWatchRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs'
Outputs:
APIGWID:
Description: API gateway Id
Value: !Ref ApiGateway