How-to: Create Lightsail Instances using AWS CLI 2.0 and Lightsail API

In this video, we will walk-through setting up new instances in Lightsail using the AWS CLI. The is a tool will allow us access many of the AWS Lightsail APIs. We’ll use a few of them today create new instances from the blueprints and from existing Lightsail snapshots . If you create frequent instances for various projects or clients you can put these commands in a batch script and run them without needing to log onto the Web Dashboard. This can be helpful for other use cases like if you’re providing web hosting services, you can connect these APIs to your sign up process to automate the provisioning of a Lightsail Instance for the customer.  So without further ado let’s see how to set this up on your computer.

API Documentation on AWS Lightsail and AWS CLI 2.0

Lightsail API Reference:

https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_Operations.html

Link to specific CLI commands used in the video:

https://docs.aws.amazon.com/cli/latest/reference/lightsail/allocate-static-ip.html

https://docs.aws.amazon.com/cli/latest/reference/lightsail/attach-static-ip.html

https://docs.aws.amazon.com/cli/latest/reference/lightsail/create-instances.html

https://docs.aws.amazon.com/cli/latest/reference/lightsail/create-instances-from-snapshot.html

High-level AWS Tuturial:

https://lightsail.aws.amazon.com/ls/docs/en_us/articles/lightsail-how-to-create-larger-instance-from-snapshot-using-aws-cli

Steps:

  • Install AWS CLI – V2. If you have version 1, uninstall that one and install V2 – https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
  • Generate Keys
    • Click on AWS link from the Lightsail Console.
    • Search for IAM and go there
    • Click on your username at the top bar.
    • Select My Security Credentials
    • Select Access Keys
    • Create New Access key
    • Download the csv file
  • In a powershell window or linux terminal run 'aws configure'
  • Paste the Access key when prompted
  • Paste the Sercret Key when prompted
  • Select the default region where most of your servers are installed. (e.g. us-east-1)
    • You can find list of regions from the Lightsail Dashboard (create instance process)
  • Output format json – Default is JSON for the response format.
  • Create your first instance using CLI
    • aws lightsail get-blueprints
    • aws lightsail get-bundles
  • Find the bundle-id you want to use and the blueprint-id
  • Create a WordPress Instance from Blueprint
    • aws lightsail create-instances --instance-names [INSTANCENAME] --availability-zone us-east-1a --blueprint-id wordpress --bundle-id nano_2_0
  • Create a Static IP
    • aws lightsail allocate-static-ip --static-ip-name [STATICIP NAME]
  • Attach the static IP
    • aws lightsail attach-static-ip  --static-ip-name [STATICIP-NAME] --instance-name [INSTANCENAME]
  • Setup a manual snapshot
    • Create Snapshot
    • Once the Snapshot is created,
    • Create Instance from Snapshot.
      • aws lightsail get-instance-snapshots
      • You will see the Instance Snapshot details
      • Copy the name value.
      • aws lightsail create-instances-from-snapshot --instance-names MyNewInstanceFromSnapshot --availability-zone us-east-1a --instance-snapshot-name [NAMECOPIED] --bundle-id medium_1_0
      • aws lightsail attach-static-ip  –static-ip-name [STATICIP-NAME] –instance-name [INSTANCENAME]
  • You should see output that status is “Started”
  • You can see the instance in your lightsail dashboard as well.
  • Next steps, put the command in a batch file to create instances with just double click

You can delete instances using the CLI and Lightsail API as well:

Video Index:

  • 00:00 – Intro
  • 01:09 – Overview
  • 02:26 – Documentation Review
  • 05:27 – Install AWS CLI v2.0
  • 06:57 – Generate AWS Access Key and Secret Keys
  • 08:23 – Configure AWS CLI with AWS Account
  • 10:18 – Create Instance using Lightsail API
  • 15:46 – Create Static IP using Lightsail API
  • 16:56 – Attach Static IP using Lightail API
  • 18:48 – Create Instance from Lightsail Manual Snapshots

All videos tutorials on the website as well as the YouTube channel aim to provide a simplified process for a specific scenario; there could be many different factors and unique use cases you may have. The tutorials may not cover every situation; so treat is as a starting point or learning concept to apply to your unique situations, and consider this inspiration but not prescription or explicit direction.

Scroll to Top