-
Notifications
You must be signed in to change notification settings - Fork 2
/
c1asLambdaDemoHelloWorld.yml
154 lines (136 loc) · 4.71 KB
/
c1asLambdaDemoHelloWorld.yml
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
149
150
151
152
153
154
AWSTemplateFormatVersion: "2010-09-09"
Description: An Image Classification app using Lambda with a vulnerability for demos.
Resources:
ApiGateway:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: "ApplicationSecuritySampleApp"
Description: "API Gateway for a sample app using Application Security"
BinaryMediaTypes:
- "multipart/form-data"
ApiGatewayRootMethod:
Type: "AWS::ApiGateway::Method"
Properties:
AuthorizationType: "NONE"
HttpMethod: "ANY"
Integration:
IntegrationHttpMethod: "POST"
Type: "AWS_PROXY"
Uri: !Sub
- "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations"
- lambdaArn: !GetAtt "LambdaApiGatewayHandler.Arn"
ResourceId: !GetAtt "ApiGateway.RootResourceId"
RestApiId: !Ref "ApiGateway"
ApiGatewayDeployment:
Type: "AWS::ApiGateway::Deployment"
DependsOn:
- "ApiGatewayRootMethod"
Properties:
RestApiId: !Ref "ApiGateway"
StageName: "release"
LambdaApiGatewayHandler:
Type: "AWS::Lambda::Function"
Properties:
Description: "Simple API Gateway Handler"
Environment:
Variables:
TREND_AP_KEY: 22bddc9a-a5bb-404a-bb7b-9f4f9a8d0334
TREND_AP_SECRET: c32bbc36-cece-45ef-ad96-57d43748eb86
TREND_AP_READY_TIMEOUT: 30
TREND_AP_TRANSACTION_FINISH_TIMEOUT: 10
TREND_AP_MIN_REPORT_SIZE: 1
TREND_AP_INITIAL_DELAY_MS: 1
TREND_AP_MAX_DELAY_MS: 100
TREND_AP_HTTP_TIMEOUT: 5
TREND_AP_PREFORK_MODE: False
TREND_AP_CACHE_DIR: /tmp/trend_cache
TREND_AP_LOG_FILE: STDERR"
Runtime: python3.7
Handler: index.handler
Code:
ZipFile: |
def handler(event, context):
print("EVENT: %s" % (event,))
content = ""
if event.get("queryStringParameters") and 'file' in event["queryStringParameters"]:
filename = event["queryStringParameters"]['file']
try:
with open(filename, 'r') as f:
content = f.read()
content = content.replace('\0', '\n')
except BaseException:
return _403()
BODY = """<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h3>Hello World</h3>
<form method="POST" action="" enctype="multipart/form-data">
<input type="text" name="hello"/>
<input type="file" name="content" />
<input type="submit" />
</form>
<pre>%s</pre>
</body>
""" % content
return {
'statusCode': 200,
'headers': {
'Content-Type': 'text/html; charset=utf8'
},
'isBase64Encoded': False,
'body': BODY,
}
def _403():
return {
'statusCode': 403,
'headers': {
},
'isBase64Encoded': False,
'body': 'Blocked',
}
MemorySize: 512
Timeout: 15
Role: !GetAtt "LambdaApiGatewayIAMRole.Arn"
LambdaApiGatewayInvokePermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:InvokeFunction"
FunctionName: !GetAtt "LambdaApiGatewayHandler.Arn"
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGateway}/*/*/"
LambdaApiGatewayIAMRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action: "sts:AssumeRole"
Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Policies:
- PolicyName: "lambda"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "cloudwatch:PutMetricData"
Resource: "*"
- Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: arn:aws:logs:*:*:*
LambdaApiGatewayHandlerLogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName: !Join ["/", ["/aws/lambda", !Ref 'LambdaApiGatewayHandler' ]]
RetentionInDays: 3
Outputs:
ApiGatewayInvokeURL:
Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/release"