Slide 1

Slide 1 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Petra Novandi Barus Senior Developer Advocate, AWS Indonesia Deploying Laravel Microservice App using Serverless Container AWS User Group Surabaya @petrabarus

Slide 2

Slide 2 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Glad to meet you all! My name is Petra Novandi Barus 8 years happy customer of AWS ❤ Startups, DevOps, App Dev, Distributed Systems 2011 CTO & Co-founder, UrbanIndo.com 2016 Largest real-estate portal in Indonesia 2018 Acquired by 99.co (SG) 2018 Country CTO, 99.co Indonesia 2019 Developer Relations, AWS twitter.com/petrabarus t.me/petrabarus Contact

Slide 3

Slide 3 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Agenda - Containers - Microservices - Serverless - Amazon ECS - AWS Fargate - PHP on Containers - Demo

Slide 4

Slide 4 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Containers

Slide 5

Slide 5 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Common Problem: It worked on my machine, why not in prod? Local Laptop Staging / QA Production On-Prem v6.0.0 v7.0.0 v4.0.0 v7.0.0

Slide 6

Slide 6 text

© 2020, Amazon Web Services, Inc. or its Affiliates. The Problem • Different application stacks • Different hardware deployment environments • How to run all applications across different environments? • How to easily migrate from one environment to another? Static website Web fronted Background workers User DB Analytics DB Queue Dev VM QA Server Single Prod Server Onsite Cluster Public Cloud Team laptop Customer Servers

Slide 7

Slide 7 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Container Solution • Unit of software delivery • Lightweight, portable, consistent • Deploy and run everywhere • Deploy and run anything • Bridge between dev and ops Static website Web fronted Background workers User DB Analytics DB Queue Dev VM QA Server Single Prod Server Onsite Cluster Public Cloud Contributor’s laptop Customer Servers

Slide 8

Slide 8 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Microservices

Slide 9

Slide 9 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Basic Concepts and Definitions Completely independent Monolith Microservices Miniservices ?

Slide 10

Slide 10 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Original Monolithic Application - example Load Balancer Browser Database Webserver Data Access Service • On-premises • Tightly coupled application components • Load balancer • Relational Database App Service Visualization Service

Slide 11

Slide 11 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Hard to Scale Can’t Handle Component Failures Slow Deployment Process Limited options Monolithic applications - limitations

Slide 12

Slide 12 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Microservices architectures Mobile client Client IoT API Gateway Account DB Shipping DB Inventory DB Store Front Web App Account Lookup Shipment Query Inventory Query

Slide 13

Slide 13 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Challenge Managing Multiple Containers Mobile client Client IoT API Gateway Account DB Shipping DB Inventory DB Store Front Web App Account Lookup Shipment Query Inventory Query

Slide 14

Slide 14 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Can’t fit a monolith inside Lambda Lambda function Webserver Data Access Service App service Visualization Service Integration services InfoSec services APIs APIs APIs APIs Hooks Hooks Logging Monitoring Limitations: • Memory • Storage • Package size • Environment variables

Slide 15

Slide 15 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Serverless

Slide 16

Slide 16 text

© 2020, Amazon Web Services, Inc. or its Affiliates. What is serverless? No infrastructure provisioning, no management Automatic scaling Pay for value Highly available and secure

Slide 17

Slide 17 text

© 2020, Amazon Web Services, Inc. or its Affiliates. AWS Lambda AWS Fargate Amazon API Gateway Amazon SNS Amazon SQS AWS Step Functions COMPUTE DATA STORES INTEGRATION Amazon Aurora Serverless Amazon S3 Amazon DynamoDB AWS AppSync

Slide 18

Slide 18 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon ECS

Slide 19

Slide 19 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Amazon Elastic Container Service

Slide 20

Slide 20 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Scheduling and Orchestration Cluster Manager Placement Engine ECS

Slide 21

Slide 21 text

© 2020, Amazon Web Services, Inc. or its Affiliates. AWS Fargate

Slide 22

Slide 22 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential Without Fargate, you end up managing more than just containers EC2 Instance ECS Agent Docker Agent OS

Slide 23

Slide 23 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential - Patching and Upgrading OS, agents, etc. - Scaling the instance fleet for optimal utilization

Slide 24

Slide 24 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential Amazon Elastic Container Service

Slide 25

Slide 25 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential Amazon Elastic Container Service AWS Fargate run serverless containers

Slide 26

Slide 26 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential Your containerized applications Managed by AWS No EC2 Instances to provision, scale or manage Elastic Scale up & down seamlessly. Pay only for what you use Integrated with the AWS ecosystem: VPC Networking, Elastic Load Balancing, IAM Permissions, CloudWatch and more AWS Fargate

Slide 27

Slide 27 text

© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Picking a Compute Platform: Containers vs. Lambda

Slide 28

Slide 28 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Containerized PHP Best Practices

Slide 29

Slide 29 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Best Practices - Stateless / Share Nothing - Decouple Processes Into Multiple Containers - Never Store External Configuration Inside Container

Slide 30

Slide 30 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Stateless / Share Nothing Process Local filesystem / memory only for short cache Store sessions/asset/data in centralized • File/Asset → S3 • Sessions → DynamoDB • PHP store session in local by default → Linux: /tmp/sess_xxxxxx • Use AWS PHP SDK session store • Database → RDS/DynamoDB • Cache → Elasticache

Slide 31

Slide 31 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Sessions

Slide 32

Slide 32 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Decouple Processes Into Multiple Containers - ”One concerns per container” ~ Docker - Benefits - Reusability - Security & Isolation - Easy to Monitor and Debug

Slide 33

Slide 33 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Never Store External Configuration Inside Container - Container should be able to run in multiple environment - Store configurations in - Environment Variables - Parameter Store - Secrets Manager

Slide 34

Slide 34 text

© 2020, Amazon Web Services, Inc. or its Affiliates. What’s Next?

Slide 35

Slide 35 text

© 2020, Amazon Web Services, Inc. or its Affiliates. ECS Service Discovery

Slide 36

Slide 36 text

© 2020, Amazon Web Services, Inc. or its Affiliates. AWS X-Ray

Slide 37

Slide 37 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Demo Link: - https://github.com/petrabarus/aws-sample-laravel-microservices - https://github.com/petrabarus/aws-sample-php-container-ecs

Slide 38

Slide 38 text

© 2020, Amazon Web Services, Inc. or its Affiliates. Thank You! @petrabarus