-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
executable file
·168 lines (151 loc) · 5.09 KB
/
application.py
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import logging
import logging.handlers
from wsgiref.simple_server import make_server, WSGIServer
from SocketServer import ThreadingMixIn
# Create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# Handler
LOG_FILE = '/tmp/sample-app/sample-app.log'
handler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1048576, backupCount=5)
handler.setLevel(logging.INFO)
# Formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Add Formatter to Handler
handler.setFormatter(formatter)
# add Handler to Logger
logger.addHandler(handler)
welcome = """
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--
Copyright 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
http://aws.Amazon/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
<style>
body {
color: #ffffff;
background-color: #E0E0E0;
font-family: Arial, sans-serif;
font-size:14px;
-moz-transition-property: text-shadow;
-moz-transition-duration: 4s;
-webkit-transition-property: text-shadow;
-webkit-transition-duration: 4s;
text-shadow: none;
}
body.blurry {
-moz-transition-property: text-shadow;
-moz-transition-duration: 4s;
-webkit-transition-property: text-shadow;
-webkit-transition-duration: 4s;
text-shadow: #fff 0px 0px 25px;
}
a {
color: #0188cc;
}
.textColumn, .linksColumn {
padding: 2em;
}
.textColumn {
position: absolute;
top: 0px;
right: 50%;
bottom: 0px;
left: 0px;
text-align: right;
padding-top: 11em;
background-color: #24B8EB;
}
.textColumn p {
width: 75%;
float:right;
}
.linksColumn {
position: absolute;
top:0px;
right: 0px;
bottom: 0px;
left: 50%;
background-color: #A9A9A9;
}
h1 {
font-size: 500%;
font-weight: normal;
margin-bottom: 0em;
}
h2 {
font-size: 200%;
font-weight: normal;
margin-bottom: 0em;
}
ul {
padding-left: 1em;
margin: 0px;
}
li {
margin: 1em 0em;
}
</style>
</head>
<body id="sample">
<div class="textColumn">
<h1>Congratulations!</h1>
<p>Your Docker Container is now running in Elastic Beanstalk on your own dedicated environment in the AWS Cloud.</p>
<p>This environment is launched with Elastic Beanstalk Docker Platform</p>
</div>
<div class="linksColumn">
<h2>Video Tutorials</h2>
<ul>
<li>YouTube: <a href="https://www.youtube.com/watch?v=lBu7Ov3Rt-M&feature=youtu.be">Run a Docker Container from the Docker Registry</a></li>
<li>YouTube: <a href="https://www.youtube.com/watch?v=pLw6MLqwmew&feature=youtu.be">Use Private Docker Repositories</a></li>
</ul>
<h2>Sample Apps</h2>
<ul>
<li>GitHub: <a href="https://github.com/awslabs/eb-demo-php-simple-app/tree/docker-apache">PHP and Amazon RDS</a></li>
<li>GitHub: <a href="https://github.com/awslabs/eb-py-flask-signup/tree/docker">Python, DynamoDB, and SNS</a></li>
</ul>
<h2>Documentation</h2>
<ul>
<li><a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.html">Deploying Docker with AWS Elastic Beanstalk</a></li>
<li><a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/">AWS Elastic Beanstalk overview</a></li>
<li><a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/index.html?concepts.html">AWS Elastic Beanstalk concepts</a></li>
</ul>
</div>
</body>
</html>
"""
def application(environ, start_response):
path = environ['PATH_INFO']
method = environ['REQUEST_METHOD']
if method == 'POST':
try:
if path == '/':
request_body_size = int(environ['CONTENT_LENGTH'])
request_body = environ['wsgi.input'].read(request_body_size)
logger.info("Received message: %s" % request_body)
elif path == '/scheduled':
logger.info("Received task %s scheduled at %s", environ['HTTP_X_AWS_SQSD_TASKNAME'], environ['HTTP_X_AWS_SQSD_SCHEDULED_AT'])
except (TypeError, ValueError):
logger.warning('Error retrieving request body for async work.')
response = ''
else:
response = welcome
status = '200 OK'
headers = [('Content-type', 'text/html')]
start_response(status, headers)
return [response]
class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
pass
if __name__ == '__main__':
httpd = make_server('', 8000, application, ThreadingWSGIServer)
print "Serving on port 8000..."
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass