├── .gitignore ├── Chapter02 ├── codecommit.tf ├── example.tf ├── main.tf ├── terraform_install.sh └── users.tf ├── Chapter03 ├── aws_s3_bucket_Using object lifecycle.txt ├── aws_s3_bucket_Using replication configuration.txt ├── cloudpatterns-zone.tf ├── gtm.tf ├── instanceAZ1c.tf ├── instances.tf ├── loadbalancer.tf ├── ltm.tf ├── main.tf ├── vpc.tf └── web-sg.tf ├── Chapter04 ├── Custom IAM Policy.txt ├── aws_cognito_identity_pool.txt ├── aws_flow_log.txt └── aws_network_acl.txt ├── Chapter05 ├── bucket-state.tf ├── buildspec.yml ├── chapter5vars.tf ├── cloudpatterns.tfplan ├── cloudpatterns_lambda.zip ├── codebuild.tf ├── codetest.tf ├── lambda_terraform.tf ├── main.tf ├── private.tf ├── sonarqube.yml └── terraform.py ├── Chapter06 └── locustfile.py ├── Chapter08 ├── CloudFront.tf ├── alb.tf ├── alb_lambda.js ├── cloudfront_lambda.js ├── cloudfront_lambda_terraform.tf └── main.tf ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf -------------------------------------------------------------------------------- /Chapter02/codecommit.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | 3 | region = "us-east-1" 4 | } 5 | data "aws_codecommit_repository" "cloudpatterns" { 6 | repository_name = "cloudpatternsrepo" 7 | } -------------------------------------------------------------------------------- /Chapter02/example.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | 3 | region = "us-east-1" 4 | } 5 | resource "aws_instance" "example" { 6 | ami = "ami-2757f631" 7 | instance_type = "t2.micro" 8 | availability_zone = "us-east-1f" 9 | } 10 | output "id" { 11 | value = "${aws_instance.example.id}" 12 | } -------------------------------------------------------------------------------- /Chapter02/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | 3 | region = "us-east-1" 4 | } -------------------------------------------------------------------------------- /Chapter02/terraform_install.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | mkdir download 3 | cd download/ 4 | wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip 5 | unzip terraform_0.11.7_linux_amd64.zip 6 | mv terraform /usr/bin/terraform 7 | terraform 8 | exit -------------------------------------------------------------------------------- /Chapter02/users.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_user" "cloudpatterns" { 2 | name = "loadbalancer" 3 | } 4 | 5 | resource "aws_iam_group_membership" "admin" { 6 | name = "tf-admin-group-membership" 7 | 8 | users = [ 9 | "${aws_iam_user.cloudpatterns.name}", 10 | ] 11 | 12 | group = "${aws_iam_group.group.name}" 13 | } 14 | 15 | resource "aws_iam_group" "group" { 16 | name = "cloudpatterngroup" 17 | } 18 | 19 | resource "aws_iam_group_policy_attachment" "test-attach" { 20 | group = "${aws_iam_group.group.name}" 21 | policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" 22 | } 23 | -------------------------------------------------------------------------------- /Chapter03/aws_s3_bucket_Using object lifecycle.txt: -------------------------------------------------------------------------------- 1 | resource "aws_s3_bucket" "bucket" { 2 | bucket = "my-bucket" 3 | acl = "private" 4 | 5 | lifecycle_rule { 6 | id = "log" 7 | enabled = true 8 | 9 | prefix = "log/" 10 | 11 | tags = { 12 | "rule" = "log" 13 | "autoclean" = "true" 14 | } 15 | 16 | transition { 17 | days = 30 18 | storage_class = "STANDARD_IA" # or "ONEZONE_IA" 19 | } 20 | 21 | transition { 22 | days = 60 23 | storage_class = "GLACIER" 24 | } 25 | 26 | expiration { 27 | days = 90 28 | } 29 | } 30 | 31 | lifecycle_rule { 32 | id = "tmp" 33 | prefix = "tmp/" 34 | enabled = true 35 | 36 | expiration { 37 | date = "2016-01-12" 38 | } 39 | } 40 | } 41 | 42 | resource "aws_s3_bucket" "versioning_bucket" { 43 | bucket = "my-versioning-bucket" 44 | acl = "private" 45 | 46 | versioning { 47 | enabled = true 48 | } 49 | 50 | lifecycle_rule { 51 | prefix = "config/" 52 | enabled = true 53 | 54 | noncurrent_version_transition { 55 | days = 30 56 | storage_class = "STANDARD_IA" 57 | } 58 | 59 | noncurrent_version_transition { 60 | days = 60 61 | storage_class = "GLACIER" 62 | } 63 | 64 | noncurrent_version_expiration { 65 | days = 90 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Chapter03/aws_s3_bucket_Using replication configuration.txt: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "eu-west-1" 3 | } 4 | 5 | provider "aws" { 6 | alias = "central" 7 | region = "eu-central-1" 8 | } 9 | 10 | resource "aws_iam_role" "replication" { 11 | name = "tf-iam-role-replication-12345" 12 | 13 | assume_role_policy = < { 4 | const request = event; 5 | const headers = request.headers; 6 | 7 | if (request.path !== '/') { 8 | // do not process if this is not an A-B test request 9 | callback(null, request); 10 | return; 11 | } 12 | 13 | const cookieExperimentA = 'X-Experiment-Name=A'; 14 | const cookieExperimentB = 'X-Experiment-Name=B'; 15 | const pathExperimentA = '/index.html'; 16 | const pathExperimentB = '/indexB.html'; 17 | 18 | let experimentUri; 19 | if (headers.cookie == cookieExperimentB ) { 20 | console.log('Experiment B cookie found'); 21 | experimentUri = pathExperimentB; 22 | } else { 23 | console.log('No valid cookie found'); 24 | experimentUri = pathExperimentA; 25 | } 26 | 27 | if (!experimentUri) { 28 | console.log('Experiment cookie has not been found. Throwing dice...'); 29 | if (Math.random() < 0.75) { 30 | experimentUri = pathExperimentA; 31 | } else { 32 | experimentUri = pathExperimentB; 33 | } 34 | } 35 | 36 | request.uri = experimentUri; 37 | console.log(`Request uri set to "${request.uri}"`); 38 | callback(null, request); 39 | }; -------------------------------------------------------------------------------- /Chapter08/cloudfront_lambda.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | const request = event.Records[0].cf.request; 5 | const headers = request.headers; 6 | 7 | if (request.uri !== '/index.html') { 8 | // do not process if this is not an A-B test request 9 | callback(null, request); 10 | return; 11 | } 12 | 13 | const cookieExperimentA = 'X-Experiment-Name=A'; 14 | const cookieExperimentB = 'X-Experiment-Name=B'; 15 | const pathExperimentA = '/index.html'; 16 | const pathExperimentB = '/indexB.html'; 17 | 18 | let experimentUri; 19 | if (headers.cookie) { 20 | for (let i = 0; i < headers.cookie.length; i++) { 21 | if (headers.cookie[i].value.indexOf(cookieExperimentA) >= 0) { 22 | console.log('Experiment A cookie found'); 23 | experimentUri = pathExperimentA; 24 | break; 25 | } else if (headers.cookie[i].value.indexOf(cookieExperimentB) >= 0) { 26 | console.log('Experiment B cookie found'); 27 | experimentUri = pathExperimentB; 28 | break; 29 | } 30 | } 31 | } 32 | 33 | if (!experimentUri) { 34 | console.log('Experiment cookie has not been found. Throwing dice...'); 35 | if (Math.random() < 0.75) { 36 | experimentUri = pathExperimentA; 37 | } else { 38 | experimentUri = pathExperimentB; 39 | } 40 | } 41 | 42 | request.uri = experimentUri; 43 | console.log(`Request uri set to "${request.uri}"`); 44 | callback(null, request); 45 | }; -------------------------------------------------------------------------------- /Chapter08/cloudfront_lambda_terraform.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_role" "iam_for_lambda" { 2 | name = "iam_for_lambda" 3 | 4 | assume_role_policy = <Implementing Cloud Design Patterns for AWS - Second Edition 4 | 5 | This is the code repository for [Implementing Cloud Design Patterns for AWS - Second Edition](https://www.packtpub.com/virtualization-and-cloud/implementing-cloud-design-patterns-aws-second-edition?utm_source=github&utm_medium=repository&utm_campaign=9781789136203), published by Packt. 6 | 7 | **Create highly efficient design patterns for scalability, redundancy, and high availability in the AWS Cloud** 8 | 9 | ## What is this book about? 10 | Whether you're just getting your feet wet in cloud infrastructure or already creating complex systems, this book will guide you through using the patterns to fit your system needs. 11 | 12 | * This book covers the following exciting features: 13 | * Implement scaling policies on schedules, influxes in traffic, and deep health checks 14 | * Make complete use of highly available and redundant storage 15 | * Design content delivery networks to improve user experience 16 | * Optimize databases through caching and sharding 17 | 18 | If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1789136202) today! 19 | 20 | https://www.packtpub.com/ 22 | 23 | ## Instructions and Navigations 24 | All of the code is organized into folders. For example, Chapter02. 25 | 26 | The code will look like the following: 27 | ``` 28 | provider "aws" { 29 | region = "us-east-1" 30 | } 31 | resource "aws_codecommit_repository" "cloudpatterns" { 32 | repository_name = "cloudpatternsrepo" 33 | description = "This is a demonstration repository for the AWS Cloud 34 | Patterns book." 35 | } 36 | ``` 37 | 38 | **Following is what you need for this book:** 39 | If you’re an architect, solution provider, or DevOps community member looking to implement repeatable patterns for deploying and maintaining services in the Amazon cloud infrastructure, this book is for you. 40 | You’ll need prior experience of using AWS understand key concepts covered in the book, as it focuses on the patterns rather than the basics of using AWS. 41 | 42 | With the following software and hardware list you can run all code files present in the book (Chapter 1-13). 43 | ### Software and Hardware List 44 | | Chapter | Software required | OS required | 45 | | -------- | ------------------------------------ | ----------------------------------- | 46 | | All | AWS subscription | Windows, Mac OS X, and Linux (Any) | 47 | 48 | ### Related products 49 | * Designing AWS Environments [[Packt]](https://prod.packtpub.com/in/virtualization-and-cloud/designing-aws-environments?utm_source=github&utm_medium=repository&utm_campaign=) [[Amazon]](https://www.amazon.com/dp/1789535549) 50 | 51 | * Expert AWS Development [[Packt]](https://prod.packtpub.com/in/virtualization-and-cloud/expert-aws-development?utm_source=github&utm_medium=repository&utm_campaign=) [[Amazon]](https://www.amazon.com/dp/1788477588) 52 | 53 | 54 | ## Get to Know the Author 55 | **Sean Keery** 56 | began hacking obscure video game systems at the age of 13. Sean then developed interpersonal skills while teaching snowboarding. Nowadays, Cloud Foundry, choreography, containers and plenty of .io. Cluster deployments, IaaS independence, and his studies for a master's in data science keep Sean occupied. The daily commute is filled with podcasts and chipmunk bunny hops. Some family time, spicy food, a good book, and wrecking the latest toys keep Sean busy at home. 57 | 58 | 59 | **Clive Harber** 60 | has been programming computers since he was 13, when Commodore Basic was all the rage and the internet, as an idea, was something that was only just starting to appear in films such as WarGames. Fast-forward a decade, he gained a master's degree in chemical engineering from University of Wales, Swansea, which he used briefly in a stint when he worked in a semi-conductor foundry making microchips. Not being totally satisfied with this, he decided to change fields and learn how to write stuff for the internet. Now, he runs his own consultancy, Distorted Thinking, providing services to organizations that find themselves in digital transition, whether that's software changes or infrastructure to cloud service migration. 61 | 62 | **Marcus Young** 63 | obtained a degree in computer science and mathematics before getting involved in system administration and DevOps. He currently works in software automation using open source tools and technologies. His hobbies include playing ice hockey and brewing homebrew beer. He also enjoys hardware projects based on microcontrollers and single-board computers. 64 | 65 | 66 | ## Other books by the authors 67 | [Implementing Cloud Design Patterns for AWS](https://www.packtpub.com/web-development/implementing-cloud-design-patterns-aws?utm_source=github&utm_medium=repository&utm_campaign=) 68 | 69 | 70 | ### Suggestions and Feedback 71 | [Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions. 72 | 73 | 74 | --------------------------------------------------------------------------------