-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
153 lines (137 loc) · 4.87 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
import logging.handlers
# Create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# Handler
LOG_FILE = '/tmp/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/
Hello Chris P
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: #1BA86D;
background-image: -moz-radial-gradient(left top, circle, #6AF9BD 0%, #00B386 60%);
background-image: -webkit-gradient(radial, 0 0, 1, 0 0, 500, from(#6AF9BD), to(#00B386));
}
.textColumn p {
width: 75%;
float:right;
}
.linksColumn {
position: absolute;
top:0px;
right: 0px;
bottom: 0px;
left: 50%;
background-color: #E0E0E0;
}
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 first AWS Elastic Beanstalk Python Application is now running on your own dedicated environment in the AWS Cloud</p>
<p>This environment is launched with Elastic Beanstalk Python Platform</p>
</div>
<div class="linksColumn">
<h2>What's Next?</h2>
<ul>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/">AWS Elastic Beanstalk overview</a></li>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/index.html?concepts.html">AWS Elastic Beanstalk concepts</a></li>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html">Deploy a Django Application to AWS Elastic Beanstalk</a></li>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_flask.html">Deploy a Flask Application to AWS Elastic Beanstalk</a></li>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/create_deploy_Python_custom_container.html">Customizing and Configuring a Python Container</a></li>
<li><a href="http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/using-features.loggingS3.title.html">Working with Logs</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 a message.")
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
start_response("200 OK", [
("Content-Type", "text/html"),
("Content-Length", str(len(response)))
])
return [bytes(response, 'utf-8')]