Skip to content
Permalink
Browse files

Initial Commit

  • Loading branch information...
hubertc
hubertc committed Nov 25, 2017
1 parent 740770c commit 3496a049892eda39d6411be0aa7da2d1a4a630d5
Showing with 10,832 additions and 6 deletions.
  1. +10 −0 .gitignore
  2. +6 −6 README.md
  3. +54 −0 admin/lambda/aggregator.py
  4. +5 −0 admin/readme.md
  5. +37 −0 client/iridium/Dockerfile
  6. +104 −0 client/iridium/iridium.py
  7. +21 −0 client/iridium/requirements.txt
  8. +37 −0 client/magnesite/Dockerfile
  9. +104 −0 client/magnesite/magnesite.py
  10. +21 −0 client/magnesite/requirements.txt
  11. +37 −0 client/monolith/Dockerfile
  12. +153 −0 client/monolith/monolith.py
  13. +21 −0 client/monolith/requirements.txt
  14. +1 −0 index.html
  15. +44 −0 ...cessor-production-swagger-integrations,authorizers,documentation,validators,gatewayresponses.yaml
  16. +3 −0 server/admin/.ebextensions/options.config
  17. +77 −0 server/admin/admin.py
  18. +41 −0 server/admin/cron.py
  19. +20 −0 server/admin/requirements.txt
  20. +24 −0 server/dynamoDB_Cfn/insterstella888_requests_history.yaml
  21. +46 −0 server/lambdaFunctions/processInterstella8888Requests/processInterstella8888Requests.js
  22. +36 −0 workshop1/code/Dockerfile.draft
  23. +153 −0 workshop1/code/monolith.py
  24. +21 −0 workshop1/code/requirements.txt
  25. +37 −0 workshop1/hints/Dockerfile.anotherhint
  26. +36 −0 workshop1/hints/Dockerfile.hint
  27. BIN workshop1/images/0-cloudformation-create.png
  28. BIN workshop1/images/1-container-image.png
  29. BIN workshop1/images/1-docker-run-ps-attach.png
  30. BIN workshop1/images/1-ec2-IP.png
  31. BIN workshop1/images/1-ecr-monolith.png
  32. BIN workshop1/images/1-ecr-push-complete.png
  33. BIN workshop1/images/1-ecr-repo-uri.png
  34. BIN workshop1/images/1-ecr-repo.png
  35. BIN workshop1/images/2-awslogs-config.png
  36. BIN workshop1/images/2-cloudwatch-logs.png
  37. BIN workshop1/images/2-cwl-confirm.png
  38. BIN workshop1/images/2-cwl-logs.png
  39. BIN workshop1/images/2-run-task.png
  40. BIN workshop1/images/2-task-def-add-container.png
  41. BIN workshop1/images/2-task-def-new-rev.png
  42. BIN workshop1/images/2-task-state-pending.png
  43. BIN workshop1/images/2-task-state-running.png
  44. BIN workshop1/images/bonus-alb-dns.png
  45. BIN workshop1/images/bonus-alb-sg.png
  46. BIN workshop1/images/bonus-alb-sns-sub.png
  47. BIN workshop1/images/bonus-alb-target-group.png
  48. BIN workshop1/images/bonus-alb.png
  49. BIN workshop1/images/bonus-cluster.png
  50. BIN workshop1/images/bonus-ecr-images.png
  51. BIN workshop1/images/bonus-ecs-service-1.png
  52. BIN workshop1/images/bonus-ecs-service-confirm.png
  53. BIN workshop1/images/bonus-ecs-service-container.png
  54. BIN workshop1/images/bonus-ecs-service-elb.png
  55. BIN workshop1/images/bonus-ecs-service-update-count.png
  56. BIN workshop1/images/bonus-ecs-service-update.png
  57. BIN workshop1/images/bonus-ecs-service-updated-1.png
  58. BIN workshop1/images/bonus-ecs-service-updated-2.png
  59. BIN workshop1/images/bonus-ecs-service.png
  60. BIN workshop1/images/bonus-task-def-host-port.png
  61. BIN workshop1/images/starthere.png
  62. BIN workshop1/images/workshop1-bonus-lab.png
  63. BIN workshop1/images/workshop1-lab1.png
  64. BIN workshop1/images/workshop1-lab2.png
  65. +695 −0 workshop1/index.html
  66. +681 −0 workshop1/readme.md
  67. +559 −0 workshop1/starthere.yaml
  68. +37 −0 workshop2/code/iridium/Dockerfile
  69. +109 −0 workshop2/code/iridium/iridium.py
  70. +21 −0 workshop2/code/iridium/requirements.txt
  71. +37 −0 workshop2/code/magnesite/Dockerfile
  72. +109 −0 workshop2/code/magnesite/magnesite.py
  73. +21 −0 workshop2/code/magnesite/requirements.txt
  74. +37 −0 workshop2/code/monolith/Dockerfile
  75. +157 −0 workshop2/code/monolith/monolith.py
  76. +21 −0 workshop2/code/monolith/requirements.txt
  77. BIN workshop2/images/0-cloudformation-create.png
  78. BIN workshop2/images/1-awslogs-config.png
  79. BIN workshop2/images/1-cloudwatch-logs.png
  80. BIN workshop2/images/1-cwl-confirm.png
  81. BIN workshop2/images/1-cwl-logs.png
  82. BIN workshop2/images/1-ec2-IP.png
  83. BIN workshop2/images/1-ecr-latest.png
  84. BIN workshop2/images/1-ecr-monolith-uri.png
  85. BIN workshop2/images/1-ecr-push-complete.png
  86. BIN workshop2/images/1-ecr-repos.png
  87. BIN workshop2/images/1-ecs-service-mono.png
  88. BIN workshop2/images/1-task-def-add-container.png
  89. BIN workshop2/images/2-cluster-view.png
  90. BIN workshop2/images/2-cwlogs-logs.png
  91. BIN workshop2/images/2-cwlogs.png
  92. BIN workshop2/images/2-ecr-iridium.png
  93. BIN workshop2/images/2-ecr-noiridium.png
  94. BIN workshop2/images/2-edit-container.png
  95. BIN workshop2/images/2-find-instance.png
  96. BIN workshop2/images/2-find-mono-task.png
  97. BIN workshop2/images/2-iridium-running.png
  98. BIN workshop2/images/2-kill-iridium.png
  99. BIN workshop2/images/2-modify-image.png
  100. BIN workshop2/images/2-note-ip.png
  101. BIN workshop2/images/2-remove-iridium.png
  102. BIN workshop2/images/2-service-update.png
  103. BIN workshop2/images/2-service-updated.png
  104. BIN workshop2/images/2-task-def-new-rev.png
  105. BIN workshop2/images/4-alb-sg.png
  106. BIN workshop2/images/4-alb-target-group.png
  107. BIN workshop2/images/4-alb.png
  108. BIN workshop2/images/4-ecs-net-1.png
  109. BIN workshop2/images/4-ecs-net-2.png
  110. BIN workshop2/images/4-ecs-service.png
  111. BIN workshop2/images/4-elb-path.png
  112. BIN workshop2/images/4-task-def-host-port.png
  113. BIN workshop2/images/after.png
  114. BIN workshop2/images/before.png
  115. BIN workshop2/images/starthere.png
  116. BIN workshop2/images/workshop2-lab1.png
  117. BIN workshop2/images/workshop2-lab2.png
  118. BIN workshop2/images/workshop2-lab3.png
  119. +122 −0 workshop2/index.html
  120. +727 −0 workshop2/readme.md
  121. +619 −0 workshop2/starthere.yaml
  122. +704 −0 workshop3/3-starthere.yaml
  123. +37 −0 workshop3/code/iridium/Dockerfile
  124. +18 −0 workshop3/code/iridium/buildspec.yml.draft
  125. +29 −0 workshop3/code/iridium/finalhintspec.yml
  126. +18 −0 workshop3/code/iridium/hintspec.yml
  127. +127 −0 workshop3/code/iridium/iridium.py
  128. +21 −0 workshop3/code/iridium/requirements.txt
  129. +103 −0 workshop3/code/iridium/service.yaml
  130. +10 −0 workshop3/code/iridium/test-cfn-nag.yml
  131. +37 −0 workshop3/code/magnesite/Dockerfile
  132. +104 −0 workshop3/code/magnesite/magnesite.py
  133. +21 −0 workshop3/code/magnesite/requirements.txt
  134. +37 −0 workshop3/code/monolith/Dockerfile
  135. +153 −0 workshop3/code/monolith/monolith.py
  136. +21 −0 workshop3/code/monolith/requirements.txt
  137. +26 −0 workshop3/generateindex.sh
  138. +1 −0 workshop3/hints/fail
  139. +670 −0 workshop3/index.html
  140. +388 −0 workshop3/interstella-lab3-instructions copy.md
  141. +665 −0 workshop3/readme.md
  142. +61 −0 workshop3/service.yaml
  143. +39 −0 workshop4/code/gatling/Dockerfile
  144. +132 −0 workshop4/code/gatling/conf/gatling.conf
  145. +8 −0 workshop4/code/gatling/run.sh
  146. +73 −0 workshop4/code/gatling/user-files/simulations/advanced/SimulationA.scala
  147. +66 −0 workshop4/code/gatling/user-files/simulations/basic/Simulation1.scala
  148. +37 −0 workshop4/code/iridium/Dockerfile
  149. +125 −0 workshop4/code/iridium/iridium.py
  150. +21 −0 workshop4/code/iridium/requirements.txt
  151. +37 −0 workshop4/code/magnesite/Dockerfile
  152. +127 −0 workshop4/code/magnesite/magnesite.py
  153. +21 −0 workshop4/code/magnesite/requirements.txt
  154. +37 −0 workshop4/code/monolith/Dockerfile
  155. +159 −0 workshop4/code/monolith/monolith.py
  156. +21 −0 workshop4/code/monolith/requirements.txt
  157. +694 −0 workshop4/readme.md
  158. +883 −0 workshop4/starthere.yaml
@@ -0,0 +1,10 @@
.DS_Store
*.pyc
localonly/
bin/
lib/
include/
pip-selfcheck.json
*.zip
.Python
.vscode/
@@ -1,7 +1,7 @@
## Amazon Ecs Interstella Workshop
# Interstella!
4-part workshop series:
1. Learn Docker and ECS [Introductory]
2. Break Monolith to Microservices [Intermediate]
3. CI/CD with CodePipeline [Intermediate/Advanced]
4. Advanced Microservices Operations: Load testing, Perf monitoring, Service Mesh [Advanced]

ECS workshop demo and instructions for re:Invent

## License

This library is licensed under the Apache 2.0 License.
@@ -0,0 +1,54 @@
from __future__ import print_function
import boto3
import json
import decimal
from botocore.exceptions import ClientError
from boto3.dynamodb.types import TypeDeserializer

# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
if o % 1 > 0:
return float(o)
else:
return int(o)
return super(DecimalEncoder, self).default(o)

dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table('FulfilledOrdersReqsAgg')
des = TypeDeserializer()


def lambda_handler(event, context):
for record in event['Records']:
d = {}
print(record['eventID'])
print(record['eventName'])
#print(record['dynamodb'])

if record['eventName'] == 'INSERT':
try:
for key in record['dynamodb']['NewImage']:
d[key] = des.deserialize(record['dynamodb']['NewImage'][key])
apiKey = d['APIKey']

response = table.update_item(
Key={
'APIKey': apiKey
},
UpdateExpression="SET resources = if_not_exists(resources, :start) + :val",
ExpressionAttributeValues={
':val': decimal.Decimal(1),
':start': 0,
},
ReturnValues="UPDATED_NEW"
)

print("UpdateItem succeeded:")
print(json.dumps(response, indent=4, cls=DecimalEncoder))
except ClientError as e:
print("SOMETHING WENT WRONG")
print(e)

print('Successfully processed %s records.' % str(len(event['Records'])))
@@ -0,0 +1,5 @@
# Instructions for running admin components
- launch admin CF template
- note arn for SNS topic for orders
- note API gateway endpoint for fulfillment API
- note S3 website URL
@@ -0,0 +1,37 @@
FROM ubuntu:14.04

ENV PRODUCT iridium

RUN apt-get -y update

RUN apt-get -y install \
git \
wget \
python-dev \
python-virtualenv \
libffi-dev \
libssl-dev

WORKDIR /root

RUN wget https://bootstrap.pypa.io/get-pip.py \
&& python get-pip.py

WORKDIR interstella

RUN virtualenv ${PRODUCT}

WORKDIR ${PRODUCT}

RUN bin/pip install --upgrade pip && \
bin/pip install requests[security]

COPY ./requirements.txt .

RUN bin/pip install -r requirements.txt

COPY ./$PRODUCT.py .

EXPOSE 5000

ENTRYPOINT ["bin/python", "iridium.py"]
@@ -0,0 +1,104 @@
#!bin/python

import time
from flask import Flask
from flask import request
import json
import requests
import os
import boto3
from urllib2 import urlopen

# This should be the endpoint of the monolith
endpoint = os.getenv('monolithUrl')
orderTopic = os.getenv('orderTopic')
orderTopicRegion = orderTopic.split(':')[3]
portNum = 5000
resource = 'iridium'

snsClient = boto3.client('sns',region_name=orderTopicRegion)
ip = urlopen('http://169.254.169.254/latest/meta-data/public-ipv4').read().decode('utf-8')
ip = 'http://'+ip+':'+str(portNum)+'/'+resource+'/'



response = snsClient.subscribe(
TopicArn=str(orderTopic),
Protocol='http',
Endpoint=ip
)

def produceResource():
print "Producing "+resource
#time.sleep(1)
return

def fulfill(endpoint, number):
if endpoint == '':
return 'Missing endpoint'
else:
fullEndpoint = 'http://'+str(endpoint)+'/fulfill/'
data = {resource : number}
try:
response = requests.post(fullEndpoint, data=json.dumps(data))
if response.status_code == requests.codes.ok:
print response.status_code
return response.status_code
else:
response.raise_for_status()
except Exception as e:
response = e
return response

app = Flask(__name__)

# Effectively, our subscriber service.
@app.route('/'+resource+'/', methods=['POST', 'GET'])
def order():
#This is for health checking
if request.method == 'GET':
return 'Welcome to the '+resource+' microservice'
#Real requests
elif request.method == 'POST':
try:
# Is this a normal SNS payload? Try to get JSON out of it
payload = request.get_json(force=True)
if 'SubscribeURL' in payload:
print 'Incoming subscription request from SNS...'
# print payload['SubscribeURL']
print 'Sending subscription confirmation to SNS...'
response = requests.get(payload['SubscribeURL'])
# print response.status_code
if response.status_code == requests.codes.ok:
return "SNS topic subscribed!"
else:
response.raise_for_status()
elif (len(json.loads(payload['Message']))) == 1 and resource in payload['Message']:
print 'Gathering Requested Items'
produceResource()
response = fulfill(endpoint, 1)
if response == requests.codes.ok:
print 'Spice fulfilled'
return 'Your order has been fulfilled'
else:
print response
return 'Your order has NOT been fulfilled'
else:
print 'Invalid Request JSON.'
print 'The data sent was %s' % payload['Message']
except Exception as e:
# Looks like it wasn't.
print e
print 'This was not a fulfillment request. This microservice is expecting exactly {"'+resource+'": 1}'
print 'The data sent was %s' % payload['Message']
return 'We were unable to place your order'


return 'This was not a fulfillment request. This microservice is expecting exactly {"'+resource+'": 1}'

else:
# We should never get here
return "This is not the page you are looking for"

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=portNum)
@@ -0,0 +1,21 @@
Flask==0.12.2
Jinja2==2.9.6
MarkupSafe==1.0
Werkzeug==0.12.2
argparse==1.2.1
boto3==1.4.7
botocore==1.7.21
certifi==2017.7.27.1
chardet==3.0.4
click==6.7
docutils==0.14
futures==3.1.1
idna==2.6
itsdangerous==0.24
jmespath==0.9.3
python-dateutil==2.6.1
requests==2.18.4
s3transfer==0.1.11
six==1.11.0
urllib3==1.22
wsgiref==0.1.2
@@ -0,0 +1,37 @@
FROM ubuntu:14.04

ENV PRODUCT magnesite

RUN apt-get -y update

RUN apt-get -y install \
git \
wget \
python-dev \
python-virtualenv \
libffi-dev \
libssl-dev

WORKDIR /root

RUN wget https://bootstrap.pypa.io/get-pip.py \
&& python get-pip.py

WORKDIR interstella

RUN virtualenv ${PRODUCT}

WORKDIR ${PRODUCT}

RUN bin/pip install --upgrade pip && \
bin/pip install requests[security]

COPY ./requirements.txt .

RUN bin/pip install -r requirements.txt

COPY ./$PRODUCT.py .

EXPOSE 5000

ENTRYPOINT ["bin/python", "magnesite.py"]
@@ -0,0 +1,104 @@
#!bin/python

import time
from flask import Flask
from flask import request
import json
import requests
import os
import boto3
from urllib2 import urlopen

# This should be the endpoint of the monolith
endpoint = os.getenv('monolithUrl')
orderTopic = os.getenv('orderTopic')
orderTopicRegion = orderTopic.split(':')[3]
portNum = 5000
resource = 'magnesite'

snsClient = boto3.client('sns',region_name=orderTopicRegion)
ip = urlopen('http://169.254.169.254/latest/meta-data/public-ipv4').read().decode('utf-8')
ip = 'http://'+ip+':'+str(portNum)+'/'+resource+'/'



response = snsClient.subscribe(
TopicArn=str(orderTopic),
Protocol='http',
Endpoint=ip
)

def produceResource():
print "Producing "+resource
#time.sleep(1)
return

def fulfill(endpoint, number):
if endpoint == '':
return 'Missing endpoint'
else:
fullEndpoint = 'http://'+str(endpoint)+'/fulfill/'
data = {resource : number}
try:
response = requests.post(fullEndpoint, data=json.dumps(data))
if response.status_code == requests.codes.ok:
print response.status_code
return response.status_code
else:
response.raise_for_status()
except Exception as e:
response = e
return response

app = Flask(__name__)

# Effectively, our subscriber service.
@app.route('/'+resource+'/', methods=['POST', 'GET'])
def order():
#This is for health checking
if request.method == 'GET':
return 'Welcome to the '+resource+' microservice'
#Real requests
elif request.method == 'POST':
try:
# Is this a normal SNS payload? Try to get JSON out of it
payload = request.get_json(force=True)
if 'SubscribeURL' in payload:
print 'Incoming subscription request from SNS...'
# print payload['SubscribeURL']
print 'Sending subscription confirmation to SNS...'
response = requests.get(payload['SubscribeURL'])
# print response.status_code
if response.status_code == requests.codes.ok:
return "SNS topic subscribed!"
else:
response.raise_for_status()
elif (len(json.loads(payload['Message']))) == 1 and resource in payload['Message']:
print 'Gathering Requested Items'
produceResource()
response = fulfill(endpoint, 1)
if response == requests.codes.ok:
print 'Spice fulfilled'
return 'Your order has been fulfilled'
else:
print response
return 'Your order has NOT been fulfilled'
else:
print 'Invalid Request JSON.'
print 'The data sent was %s' % payload['Message']
except Exception as e:
# Looks like it wasn't.
print e
print 'This was not a fulfillment request. This microservice is expecting exactly {"'+resource+'": 1}'
print 'The data sent was %s' % payload['Message']
return 'We were unable to place your order'


return 'This was not a fulfillment request. This microservice is expecting exactly {"'+resource+'": 1}'

else:
# We should never get here
return "This is not the page you are looking for"

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=portNum)
Oops, something went wrong.

0 comments on commit 3496a04

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.