Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevOps on AWS with PowerShell

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

DevOps on AWS with PowerShell

Dev Ops on Amazon Web Services Cloud with PowerShell. Use Automation to create EC2 instances, VPC, subnets, internet gateway, NAT gateway, and Multi-AZ environments.

Avatar for Guillermo Musumeci

Guillermo Musumeci

October 21, 2016

Other Decks in Technology

Transcript

  1. PowerShell Conference Singapore 2016 Who is this guy? • Started

    my career in Microsoft, 20 years ago. • Lived in Buenos Aires, Washington DC, Madrid, Paris and Singapore. • Solutions Architect @ AWS Singapore, Microsoft SME for ASEAN. • Cloud Evangelist. Expert in automating and deploying Microsoft workloads in Amazon Web Services, Microsoft Azure & Google Cloud. • Love to create and build stuff. Developer. Entrepreneur. Curious. • Book author. Books lover. Husband & Dad. Foodie. • Startup Mentor. I ♥ Startups.
  2. PowerShell Conference Singapore 2016 What we will cover • Tools

    setup • Launching EC2 instances • Tagging resources • Creating Security Groups • Finding resources using filters • Adding storage to instances • Bootstrapping instances with UserData • Configuring VPCs and Subnets
  3. PowerShell Conference Singapore 2016 What we will cover (continued) •

    Configuring Internet Gateways and NAT Gateways • Launching RDP Gateway servers • Launching Active Directory Domain Controllers • Launching IIS Web Servers • Single-AZ Full Stack • Multi-AZ Full Stack • Elastic Load Balancer • Auto Scaling EC2 Instances
  4. PowerShell Conference Singapore 2016 Before you get started • You

    need an AWS account • PowerShell 2.0 or later installed. • Basic knowledge of some AWS services: • EC2 instances • Security Groups • VPCs and subnets
  5. PowerShell Conference Singapore 2016 Setting up the tool • Download

    and install AWS Tools for Windows PowerShell from https://aws.amazon.com/powershell/ • The installer for the Tools for Windows PowerShell installs the most recent version of the AWS SDK for .NET and also the AWS Toolkit for Visual Studio. • If you are using an AWS EC2 instance as bastion or management server, AWS Tools for Windows PowerShell is preinstalled on the Windows machine.
  6. PowerShell Conference Singapore 2016 Installing the AWS Tools for PowerShell

    Core • The AWS Tools for PowerShell Core can be installed on computers that are running Microsoft PowerShell 5.1 or a later release of PowerShell, including: • Ubuntu 14.04 LTS and later • CentOS Linux 7 • Mac OS X • Windows 8.1 Enterprise • Windows Server 2012 R2 • Windows 10 for Business • Download the AWS Tools for PowerShell Core at https://www.powershellgallery.com/packages/AWSPowerShell.NetCore
  7. PowerShell Conference Singapore 2016 Configuring the AWS Command Line Interface

    • To add a new profile to the AWS SDK store, call Set-AWSCredentials as follows: where • -AccessKey – The access key. • -SecretKey – The secret key. • -StoreAs – The profile name, which must be unique. • To specify the default profile, set the profile name to default.
  8. PowerShell Conference Singapore 2016 Configuring the AWS Command Line Interface

    • List profiles You can check the current list of names as follows: • Remove a profile To remove a profile, use the following command: • The -StoredCredentials parameter specifies the profile name.
  9. PowerShell Conference Singapore 2016 Configure the AWS region • Using

    the Get-AWSRegion command to list AWS regions available
  10. PowerShell Conference Singapore 2016 Exploring AWS PowerShell Module • Use

    the Get-Command command to lists all commands in the AWS module
  11. PowerShell Conference Singapore 2016 Exploring AWS PowerShell Module • Using

    Get-Command with the –Noun parameter to filter commands
  12. PowerShell Conference Singapore 2016 Exploring AWS PowerShell Module • Using

    Get-Command cmdlet with –Noun and –Verb parameters to filter commands
  13. PowerShell Conference Singapore 2016 Exploring AWS PowerShell Module • Using

    Help cmdlet with –Examples parameter to display examples
  14. PowerShell Conference Singapore 2016 History of AWS cmdlets • The

    $AWS-History command enumerate AWS cmdlets that are being used
  15. PowerShell Conference Singapore 2016 Compute Services 20 Auto Scaling Elastic

    Load Balancing Automated scaling of EC2 capacity Dynamic traffic distribution Amazon EC2 Elastic virtual servers in the cloud EC2 EC2 EC2 EC2 EC2 EC2 Actual EC2
  16. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Configure Security Groups. A security group acts as a virtual firewall that controls the traffic for one or more instances
  17. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Final step: select existing or create a key pair
  18. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    The Get-EC2Image cmdlet retrieves a list of AMIs that you can use.
  19. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    The Get-EC2ImageByName cmdlet filter the list of AWS Windows AMIs based on the type of server configuration you are interested in.
  20. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Getting the ImageId using the Get-EC2ImageByName cmdlet
  21. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Getting the ImageId using the Get-EC2ImageByName cmdlet
  22. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Creating an EC2 instance using New-EC2Instance cmdlet
  23. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Creating an EC2 instance using New-EC2Instance cmdlet. • Using $instance_id to capture the result of the cmdlet.
  24. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Using $instance_id to capture the result of the cmdlet. • Getting details of EC2 instance with .Instances parameter.
  25. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Using Remove-EC2Instance cmdlet to stop and terminate the EC2 Instance stored in the $ec2 variable • Use the Select –ExpandProperty to simplify your life
  26. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Using Get-EC2SecurityGroup cmdlet to list security groups
  27. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Adding the new inbound rule to the Security Group • Using the .IpPermission parameter to verify new rule was added successfully to the Security Group
  28. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Creating a new tag • Filter the Get-EC2Instance cmdlet results using tags
  29. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Using the Get-ECTag cmdlet to filter instances
  30. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Create a new EBS Block Device • Then a Block Device Mapping
  31. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Add an extra EBS drive to EC2 instance when launched • Use Get-EC2Volume cmdlet to list volumes attached to EC2 instances
  32. PowerShell Conference Singapore 2016 Building a Windows EC2 instance •

    Creating a new EBS volume • Attaching EBS volume to existing EC2 Instance
  33. PowerShell Conference Singapore 2016 Managing EC2 Instance Password • Using

    the Get-EC2PasswordData cmdlet to decrypt the administrator password for EC2 instances launched using a key pair • If you keep all key pair files in the same folder also you can type:
  34. PowerShell Conference Singapore 2016 Bootstrapping an EC2 Instance • Configuring

    Instances with User Data • Note: User data is limited to 16 KB in raw form, not base64-encoded form. User data is executed only at launch.
  35. PowerShell Conference Singapore 2016 Accessing local EC2 instance Metadata •

    Instance metadata is data about your instance that you can use to configure or manage the running instance. • You can only access instance metadata and user data from within the instance itself.
  36. PowerShell Conference Singapore 2016 Accessing local EC2 instance Metadata •

    Retrieving the metadata information from the local machine
  37. PowerShell Conference Singapore 2016 Amazon Virtual Private Cloud (VPC) •

    Provision a logically isolated section of the AWS cloud • Control your virtual networking environment • Subnets • Route Tables • Security Groups • Network ACLs • Connect to your on-premises network via hardware VPN • Control if and how your instances access the Internet
  38. PowerShell Conference Singapore 2016 Creating the VPC • Using the

    New-EC2Vpc cmdlet to create a new VPC and New-EC2Tag to tag it
  39. PowerShell Conference Singapore 2016 Creating subnets • Using the New-EC2Subnet

    cmdlet to create public and private subnets and New-EC2Tag to tag them
  40. PowerShell Conference Singapore 2016 Creating the Internet Gateway • The

    Internet Gateway connects the VPC to the Internet and to other AWS services • We using the New-EC2InternetGateway cmdlet to create a new IG and Add-EC2InternetGateway cmdlet to attach the IG to the VPC
  41. PowerShell Conference Singapore 2016 Creating the NAT Gateway • The

    NAT gateway uses Elastic IP address. This enables instances in the private subnet to send requests to the Internet • We are using the New-EC2Address cmdlet to get an Elastic IP address and then New-EC2NatGateway cmdlet to create the NAT Gateway
  42. PowerShell Conference Singapore 2016 Creating Security Groups for External Access

    • Create rules and security groups to allow RDP and SSH from internet
  43. PowerShell Conference Singapore 2016 Creating Security Groups for Internal Access

    • Create rules and security groups to allow RDP from DMZ and unrestricted access inside private subnet
  44. PowerShell Conference Singapore 2016 Creating Routes • Create public route

    table rules • Create private route table rules
  45. PowerShell Conference Singapore 2016 Building a RDP Gateway • Using

    User Data script to create the Remote Desktop Gateway • Launching the RDP Gateway on the public subnet
  46. PowerShell Conference Singapore 2016 Building a AD Domain Controller •

    Using User Data script to create an Active Directory domain controller
  47. PowerShell Conference Singapore 2016 Building a AD Domain Controller •

    Using the New-EC2Instance cmdlet and user data to automate the launch of an Active Directory domain controller on the private subnet
  48. PowerShell Conference Singapore 2016 Building a IIS Web Servers •

    Using User Data script to configure the IIS Web Server • Launching the IIS Web Server on the private subnet
  49. PowerShell Conference Singapore 2016 Creating an ELB • Creating a

    Security Group for the ELB • Creating the ELB Listener
  50. PowerShell Conference Singapore 2016 Creating an ELB (continues) • Using

    the New-ELBLoadBalancer cmdlet to launch the ELB • Configuring ELB health check settings with the Set-ELBHealthCheck cmdlet
  51. PowerShell Conference Singapore 2016 Creating an Auto Scaling group •

    Creating a Security Group for the Auto Scaling Group • User Data to bootstrap the web server
  52. PowerShell Conference Singapore 2016 Creating an Auto Scaling group (continues)

    • Using the New-ASLaunchConfiguration cmdlet to configure the EC2 instance configuration • Finally, using the New-ASAutoScalingGroup cmdlet to create and launch the Auto Scaling Group