├── Chapter09 ├── .DS_Store └── sample-weather-app │ ├── .DS_Store │ ├── .idea │ ├── misc.xml │ ├── modules.xml │ ├── sample-weather-app.iml │ └── workspace.xml │ ├── Cloudnative-weather-microservice.yaml │ ├── WeatherService.html │ ├── cloud-native-api-swagger.yaml │ └── cloudnative-weather-service.zip ├── Chapter10 ├── .DS_Store └── WeatherServiceFunction │ ├── function.json │ └── run.py ├── Chapter11 ├── index.js └── package.json ├── LICENSE ├── README.md └── Software and Hardware list.pdf /Chapter09/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Cloud-Native-Architectures/d9e98f0ef87b60d9317c21a4a34430df42d74ddb/Chapter09/.DS_Store -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Cloud-Native-Architectures/d9e98f0ef87b60d9317c21a4a34430df42d74ddb/Chapter09/sample-weather-app/.DS_Store -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/.idea/sample-weather-app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 35 | 36 | 41 | 42 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Python 57 | 58 | 59 | 60 | 61 | PyPep8Inspection 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 | 37 | 38 | 39 | OpenWeatherMap App Id (API Key): 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/cloud-native-api-swagger.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | title: "Weather Service API" 5 | basePath: "/prod" 6 | schemes: 7 | - "https" 8 | paths: 9 | /weatherservice: 10 | get: 11 | produces: 12 | - "application/json" 13 | parameters: 14 | - name: "appid" 15 | in: "query" 16 | required: true 17 | type: "string" 18 | - name: "zip" 19 | in: "query" 20 | required: true 21 | type: "string" 22 | responses: 23 | 200: 24 | description: "200 response" 25 | schema: 26 | $ref: "#/definitions/Empty" 27 | x-amazon-apigateway-request-validator: "Validate body, query string parameters,\ 28 | \ and headers" 29 | x-amazon-apigateway-integration: 30 | responses: 31 | default: 32 | statusCode: "200" 33 | uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:607195930000:function:${stageVariables.LambdaFunctionName}/invocations 34 | passthroughBehavior: "when_no_match" 35 | httpMethod: "POST" 36 | contentHandling: "CONVERT_TO_TEXT" 37 | type: "aws_proxy" 38 | options: 39 | consumes: 40 | - "application/json" 41 | produces: 42 | - "application/json" 43 | responses: 44 | 200: 45 | description: "200 response" 46 | schema: 47 | $ref: "#/definitions/Empty" 48 | headers: 49 | Access-Control-Allow-Origin: 50 | type: "string" 51 | Access-Control-Allow-Methods: 52 | type: "string" 53 | Access-Control-Allow-Headers: 54 | type: "string" 55 | x-amazon-apigateway-integration: 56 | responses: 57 | default: 58 | statusCode: "200" 59 | responseParameters: 60 | method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" 61 | method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'" 62 | method.response.header.Access-Control-Allow-Origin: "'*'" 63 | requestTemplates: 64 | application/json: "{\"statusCode\": 200}" 65 | passthroughBehavior: "when_no_match" 66 | type: "mock" 67 | definitions: 68 | Empty: 69 | type: "object" 70 | title: "Empty Schema" 71 | x-amazon-apigateway-request-validators: 72 | Validate body, query string parameters, and headers: 73 | validateRequestParameters: true 74 | validateRequestBody: true 75 | -------------------------------------------------------------------------------- /Chapter09/sample-weather-app/cloudnative-weather-service.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Cloud-Native-Architectures/d9e98f0ef87b60d9317c21a4a34430df42d74ddb/Chapter09/sample-weather-app/cloudnative-weather-service.zip -------------------------------------------------------------------------------- /Chapter10/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Cloud-Native-Architectures/d9e98f0ef87b60d9317c21a4a34430df42d74ddb/Chapter10/.DS_Store -------------------------------------------------------------------------------- /Chapter10/WeatherServiceFunction/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "function", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "post", 10 | "get" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ], 19 | "disabled": false 20 | } -------------------------------------------------------------------------------- /Chapter10/WeatherServiceFunction/run.py: -------------------------------------------------------------------------------- 1 | ## importing required libraries 2 | import os 3 | import sys 4 | import json 5 | import argparse 6 | import urllib 7 | from urllib2 import HTTPError, URLError 8 | 9 | 10 | ## response construction and return 11 | def write_http_response(status, body_dict): 12 | return_dict = { 13 | "status": status, 14 | "body": body_dict, 15 | "headers": { 16 | "Content-Type": "application/json" 17 | } 18 | } 19 | output = open(os.environ['res'], 'w') 20 | output.write(json.dumps(return_dict)) 21 | 22 | #postreqdata = json.loads(open(os.environ['req']).read()) 23 | #print postreqdata 24 | 25 | ## extract input parameter values 26 | zip = os.environ['req_query_zip'] 27 | countrycode = os.environ['req_query_countrycode'] 28 | apikey = os.environ['req_query_apikey'] 29 | 30 | print ("zip code value::" + zip + ", countrycode:" + countrycode + ", apikey::" + apikey) 31 | ## construct full URL to invoke OpenWeatherMap service with proper inputs 32 | baseUrl = 'http://api.openweathermap.org/data/2.5/weather' 33 | completeUrl = baseUrl + '?zip=' + zip + ',' + countrycode + '&appid=' + apikey 34 | print('Request URL--> ' + completeUrl) 35 | 36 | ## Invoke OpenWeatherMap API and parse response with proper exception handling 37 | try: 38 | apiresponse = urllib.urlopen(completeUrl) 39 | except IOError as e: 40 | error = "IOError - The server couldn\'t fulfill the request." 41 | print(error) 42 | print("I/O error: {0}".format(e)) 43 | errorcode = format(e[1]) 44 | errorreason = format(e[2]) 45 | write_http_response(errorcode, errorreason) 46 | except HTTPError as e: 47 | error = "The server couldn\'t fulfill the request." 48 | print(error) 49 | print('Error code: ', e.code) 50 | write_http_response(e.code, error) 51 | except URLError as e: 52 | error = "We failed to reach a server." 53 | print(error) 54 | print('Reason: ', e.reason) 55 | write_http_response(e.code, error) 56 | else: 57 | headers = apiresponse.info() 58 | print('DATE :', headers['date']) 59 | print('HEADERS :') 60 | print('---------') 61 | print(headers) 62 | print('DATA :') 63 | print('---------') 64 | response = apiresponse.read().decode('utf-8') 65 | print(response) 66 | write_http_response(200, response) 67 | -------------------------------------------------------------------------------- /Chapter11/index.js: -------------------------------------------------------------------------------- 1 | function handlePUT(req, res) { 2 | // Return Forbidden message for POST Request 3 | res.status(403).send('Forbidden!'); 4 | } 5 | 6 | function handleGET(req, res) { 7 | // Retrieve URL query parameters 8 | var zip = req.query.zip; 9 | var countrycode = req.query.countrycode; 10 | var apikey = req.query.apikey; 11 | 12 | // Create complete OpenWeatherMap URL using user-provided parameters 13 | var baseUrl = 'http://api.openweathermap.org/data/2.5/weather'; 14 | var completeUrl = baseUrl + "?zip=" + zip + "," + countrycode + "&appid=" + apikey; 15 | console.log("Request URL--> " + completeUrl) 16 | 17 | // Import the sync-request module to invoke HTTP request 18 | var weatherServiceRequest = require('sync-request'); 19 | 20 | // Invoke OpenWeatherMap API 21 | var weatherServiceResponse = weatherServiceRequest('GET', completeUrl); 22 | var ststusCode = weatherServiceResponse.statusCode; 23 | console.log("RESPONSE STATUS -->" + ststusCode); 24 | 25 | // Check if response was error or success reponse 26 | if (ststusCode < 300) { 27 | console.log("JSON BODY DATA --->>" + weatherServiceResponse.getBody()); 28 | // For Success response, return back appropriate status code, content-type and body 29 | console.log("Setting response content type to json"); 30 | res.setHeader('Content-Type', 'application/json'); 31 | res.status(ststusCode); 32 | res.send(weatherServiceResponse.getBody()); 33 | } else { 34 | console.log("ERROR RESPONSE -->" + ststusCode); 35 | //For Error response send back appropriate error details 36 | res.status(ststusCode); 37 | res.send(ststusCode); 38 | } 39 | } 40 | 41 | /** 42 | * Responds to a GET request with Weather Information. Forbids a PUT request. 43 | * 44 | * @param {Object} req Cloud Function request context. 45 | * @param {Object} res Cloud Function response context. 46 | */ 47 | exports.weatherService = (req, res) => { 48 | switch (req.method) { 49 | case 'GET': 50 | handleGET(req, res); 51 | break; 52 | case 'PUT': 53 | handlePUT(req, res); 54 | break; 55 | default: 56 | res.status(500).send({ 57 | error: 'Something blew up!' 58 | }); 59 | break; 60 | } 61 | }; -------------------------------------------------------------------------------- /Chapter11/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample-http", 3 | "version": "0.0.1", 4 | "dependencies": { 5 | "sync-request": "^2.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Cloud Native Architectures 5 | 6 | Cloud Native Architectures 7 | 8 | This is the code repository for [Cloud Native Architectures](https://www.packtpub.com/application-development/cloud-native-architectures?utm_source=github&utm_medium=repository&utm_campaign=9781787280540), published by Packt. 9 | 10 | **Design high-availability and cost-effective applications for the cloud** 11 | 12 | ## What is this book about? 13 | Cloud computing has proven to be the most revolutionary IT development since virtualization. Cloud native architectures give you the benefit of more flexibility over legacy systems. To harness this, businesses need to refresh their development models and architectures when they find they don’t port to the cloud. Cloud Native Architectures demonstrates three essential components of deploying modern cloud native architectures: organizational transformation, deployment modernization, and cloud native architecture patterns. 14 | 15 | This book covers the following exciting features: 16 | * Learn the difference between cloud native and traditional architecture 17 | * Explore the aspects of migration, when and why to use it 18 | * Identify the elements to consider when selecting a technology for your architecture 19 | * Automate security controls and configuration management 20 | * Use infrastructure as code and CICD pipelines to run environments in a sustainable manner 21 | 22 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1787280543) today! 23 | 24 | https://www.packtpub.com/ 26 | 27 | ## Instructions and Navigations 28 | All of the code is organized into folders. For example, Chapter02. 29 | 30 | The code will look like the following: 31 | ``` 32 | print('Loading function') 33 | 34 | def respond(err, res=None): 35 | return { 36 | 'statusCode': '400' if err else '200', 37 | 'body': err if err else res, 38 | 'headers': { 39 | 'Content-Type': 'application/json', 40 | }, 41 | } 42 | ``` 43 | 44 | **Following is what you need for this book:** 45 | Cloud Native Architectures is for software architects who are keen on designing resilient, scalable, and highly available applications that are native to the cloud. 46 | 47 | With the following software and hardware list you can run all code files present in the book (Chapter 1-12). 48 | ### Software and Hardware List 49 | | Chapter | Software required | OS required | 50 | | -------- | ------------------------------------ | ----------------------------------- | 51 | | 9-11 | OpenWeatherMap | Windows, Mac OS X, and Linux (Any) | 52 | | 9 | Amazon Web Services | Windows, Mac OS X, and Linux (Any) | 53 | | 10 | Microsoft Azure | Windows, Mac OS X, and Linux (Any) | 54 | | 11 | Google Cloud Platform | Windows, Mac OS X, and Linux (Any) | 55 | 56 | ### Related products 57 | * Cloud Native Development Patterns and Best Practices [[Packt]](https://www.packtpub.com/application-development/cloud-native-development-patterns-and-best-practices?utm_source=github&utm_medium=repository&utm_campaign=9781788473927) [[Amazon]](https://www.amazon.com/dp/1788473922) 58 | 59 | * Cloud Native programming with Golang [[Packt]](https://www.packtpub.com/application-development/cloud-native-programming-golang?utm_source=github&utm_medium=repository&utm_campaign=9781787125988) [[Amazon]](https://www.amazon.com/dp/178712598X) 60 | 61 | ## Get to Know the Author 62 | **Tom Laszewski** 63 | is a leader and cloud technologist who has helped ISVs, SIs, start-ups, and mid-market, and global customers modernization IT systems and develop innovative software solutions. He currently leads a team of Enterprise Technologists responsible for the business and IT transformation strategy with key AWS customers pursuing cloud modernization initiatives and digital transformation efforts utilizing cloud native architecture. He enjoys traveling the world with his teenage sons Slade and Logan. 64 | 65 | **Kamal Arora** 66 | is an inventor, author, and technology leader with more than 15 years of IT experience. He currently works at Amazon Web Services and leads a diverse team of highly experienced solutions architects who enable global consulting partners and enterprise customers on their journey to cloud. Kamal has also led the creation of biggest global technical partnerships, set his team's vision and execution model, and incubated multiple new strategic initiatives. He's passionate about the latest innovations in the cloud and the AI/ML space, and their impact on our society and daily-life. 67 | 68 | **Erik Farr** 69 | is a technology leader with over 18 years in the IT industry. He has been on the leading edge of cloud technology and enterprise architecture, working with some of the largest companies and system integrators in the world. In his current role at Amazon Web Services, he leads a team of experienced solution architects to help global system integrator partners design enterprise scale cloud native architectures. Before AWS, he has experience with Capgemini and The Walt Disney Company, always working to create highly valuable outcomes for customers. 70 | 71 | **Piyum Zonooz** 72 | is a Global Partner Solution Architect at Amazon Web Services, where he works with companies across all industries to help drive cloud adoption and re-architect products to cloud native. He's led projects in TCO analysis, infrastructure design, DevOps adoption, and complete business transformation. Prior to AWS, Piyum was a Lead Architect as part of the Accenture Cloud Practice where he led large-scale cloud adoption projects. Piyum holds a BSc and MSc. degree in Engineering from the University of Illinois at Urbana-Champaign. 73 | 74 | ## Other books by the authors 75 | [Oracle Information Integration, Migration, and Consolidation](https://www.packtpub.com/application-development/oracle-information-integration-migration-and-consolidation?utm_source=github&utm_medium=repository&utm_campaign=9781849682206) 76 | 77 | [Do more with SOA Integration: Best of Packt](https://www.packtpub.com/application-development/do-more-soa-integration-best-packt?utm_source=github&utm_medium=repository&utm_campaign=9781849685726) 78 | 79 | ### Suggestions and Feedback 80 | [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. 81 | ### Download a free PDF 82 | 83 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
84 |

https://packt.link/free-ebook/9781787280540

-------------------------------------------------------------------------------- /Software and Hardware list.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Cloud-Native-Architectures/d9e98f0ef87b60d9317c21a4a34430df42d74ddb/Software and Hardware list.pdf --------------------------------------------------------------------------------