A 60 minute Tour of AWS Compute

June 30, 2017
Talk @ AWS Loft Munich, November 2016. Slides: https://fr.slideshare.net/JulienSIMON5/a-60minute-tour-of-aws-compute-november-2016 Follow me on Twitter @julsimon

Transcript

I'm Julian, a technical evangelist with AWS, based in the Paris office. I don't really speak German, so I'll stick to English. Thank you for visiting us in the Loft. It's a pleasure to see you all. Today, I hope it will be a fun session as I walk you through the different ways of deploying code and applications to AWS. The session should last about 60 minutes, and I won't be too long. If you have questions, please ask them during the session. I'll be around afterward, and I'm also here tomorrow, so we have plenty of time to talk and answer all your questions. Before we start, let's make sure we understand who's in the room. Who has never used AWS before? Welcome, everyone. This session is for you. Who has used EC2, started virtual machines? A few people. Who has used Elastic Beanstalk? Good. ECS? Docker? No. Alright. And Lambda? More people have tried Lambda than ECS. That's interesting. You're in the right session. We'll cover all four, do a lot of demos, and hopefully answer many questions. We have four ways of deploying code for different technologies on AWS. The first is EC2, deploying virtual machines. The second is Elastic Beanstalk, a PaaS product where you only deploy your app and don't manage the underlying infrastructure. ECS allows you to manage Docker clusters. Lastly, Lambda is a new way of deploying code by deploying only stateless functions. We'll study all four. We have a blog dedicated to compute technologies, which is updated regularly. I strongly advise you to keep an eye on it to stay informed about the latest features and examples. Let's start in chronological order to see the progression of computing. The first one, EC2, is the virtual machine technology of the AWS cloud. It was launched over 10 years ago and is extremely solid, forming one of the foundations of the AWS cloud. It's a lower-level service, often called infrastructure as a service. You select an Amazon Machine Image (AMI), which could be a Linux image, a Windows image, or your own custom image. You choose an instance size, which determines CPU power, memory, network I/O, etc., and start your virtual machine. Once the virtual machine is running, you can connect to it and manage it like a normal server. EC2 is simple but powerful, offering a range of services like load balancing, monitoring, auto-scaling, and network storage (EBS). How much does it cost? You pay by the hour based on the instance size. The more powerful the instance, the more expensive it is. You start paying as soon as the instance starts, regardless of whether it's used. This is a significant difference from Lambda, which I'll cover later. Some instances from the AWS Marketplace may have additional hourly fees from the software vendor. When should you use EC2? Use it when you need full administrative control over your infrastructure. However, with great power comes great responsibility. You manage security, patching, backups, etc. Two features allow massive savings: reserved instances and spot instances. Reserved instances offer a large discount (20% to 65%) by prepaying for one or three years. Spot instances let you bid on unused EC2 capacity, potentially getting instances at up to 90% off. However, if the market price exceeds your bid, you lose the instance within two minutes. Use spot instances for stateless workloads, not critical infrastructure. To start an EC2 instance, you can use the AWS Management Console or the AWS CLI. Here's an example using the CLI: ```bash aws ec2 run-instances --image-id ami-12345678 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-12345678 --region eu-west-1 ``` This command starts a T2 micro instance with the specified AMI, key pair, security group, and region. You can manage the instance using the console or scripts. Elastic Beanstalk is a platform as a service (PaaS) that provides a full platform for developers. It supports multiple platforms like PHP, Java, .NET, etc. Developers don't need to manage infrastructure, focusing instead on writing code. Beanstalk has a simple CLI with commands for creating environments and deploying code. It includes built-in monitoring and networking. Here's a quick demo of deploying a Rails application to Beanstalk: 1. Create a new Rails app and add it to Git. 2. Use `eb init` to create a new Elastic Beanstalk application: ```bash eb init -p ruby-2.3 blog --region eu-west-1 ``` 3. Create a development environment: ```bash eb create blog-dev --single --instance-type t2.micro --keyname MyKeyPair --envvars RAILS_SECRET_TOKEN=your_secret_token ``` 4. Deploy the code: ```bash eb deploy ``` Elastic Beanstalk uses CloudFormation to automate the creation of infrastructure resources. You can create multiple environments for development, pre-production, and production. EC2 Container Service (ECS) manages Docker clusters in AWS. It's not just about running Docker on a single machine but managing a cluster of EC2 instances with Docker installed. ECS handles scheduling, high availability, and scaling. You can use the ECS CLI and CloudFormation to manage your cluster. Here's a quick demo of setting up an ECS cluster and deploying a PHP application: 1. Configure a new cluster: ```bash ecs-cli configure --cluster myCluster --region eu-west-1 --access-key YOUR_ACCESS_KEY --secret-key YOUR_SECRET_KEY ``` 2. Start the cluster: ```bash ecs-cli up --keypair MyKeyPair --capability-iam --instance-type t2.micro --size 1 ``` 3. Deploy the application using a Docker Compose file: ```yaml version: '2' services: phpdemo: image: 123456789012.dkr.ecr.us-west-2.amazonaws.com/phpdemo:latest ports: - "80:80" cpu: 100 memory: 128 ``` 4. Start the service: ```bash ecs-cli compose --project-name phpdemo service up ``` 5. Scale the cluster and the service: ```bash ecs-cli scale --size 3 ecs-cli compose --project-name phpdemo service up --target-task-count 3 ``` Lambda is a function-as-a-service (FaaS) that lets you run code without provisioning or managing servers. You only pay for the compute time you consume, and there's no charge when your code isn't running. Lambda is ideal for event-driven applications and building APIs. Here's a quick demo of creating a Lambda function and integrating it with API Gateway: 1. Write a simple Python function: ```python def lambda_handler(event, context): num1 = event['num1'] num2 = event['num2'] return num1 + num2 ``` 2. Create the Lambda function in the AWS Management Console. 3. Create an API in API Gateway and integrate it with the Lambda function. 4. Deploy the API and test it using `curl`: ```bash curl -X POST -H "Content-Type: application/json" -d '{"num1": 5, "num2": 7}' https://your-api-id.execute-api.eu-west-1.amazonaws.com/prod/add ``` In conclusion, AWS offers a range of services for deploying code, from low-level EC2 to high-level Lambda. Each has its use cases and benefits. I hope this session was helpful. Thank you for your attention, and feel free to reach out with any questions. Enjoy the rest of your day.

Tags

AWSEC2Elastic BeanstalkECSLambda