【小ネタ】AWS LightsailでblueprintIdやbundleIdを確認する【Lightsail】

# はじめに
AnsibleでLightsailインスタンスを作ることができますが、「blueprint_id」や「bundle_id」を確認する方法が一瞬分からなかったので、メモしておきます。

lightsail - Create or delete a virtual machine instance in AWS Lightsail — Ansible Documentation
https://docs.ansible.com/ansible/2.6/modules/lightsail_module.html

なお、2018/10/1現在、LightsailはCloudFormationに対応していないようです。
なので、AnsibleのPlaybookを作ることとしました。

AWS Resource Types Reference - AWS CloudFormation
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html

# TL;DR
- AWS CLIでLightsailのAPIを実行する
- jqを活用すると便利

# 確認してみる
## blueprint_id

```
$ aws lightsail get-blueprints
{
    "blueprints": [
        {
            "group": "windows_2016",
            "description": "Amazon Lightsail helps you build, deploy, scale, and manage Microsoft applications quickly, easily, and cost effectively with Windows Server 2016. For business IT applications, Lightsail runs Windows-based solutions in a secure, easily managed, and performant cloud environment. For Microsoft developers, Windows Server on Lightsail provides a flexible and agile development platform, integrated with .NET to help accelerate development cycles.",
            "platform": "WINDOWS",
            "productUrl": "https://aws.amazon.com/marketplace/pp/B01M7SJEU7",
            "version": "2018.07.11",
            "licenseUrl": "https://d7umqicpi7263.cloudfront.net/eula/product/13c2dbc9-57fc-4958-922e-a1ba7e223b0d/fdfd055c-b2ff-4c64-a699-504da826ccd4.txt",
            "versionCode": "1",
            "blueprintId": "windows_server_2016_2018_07_11",
            "minPower": 0,
            "type": "os",
            "isActive": true,
            "name": "Windows Server 2016"
        },
        {
            "group": "windows_2012",
            "description": "Amazon Lightsail helps you build, deploy, scale, and manage Microsoft applications quickly, easily, and cost effectively with Windows Server 2012 R2. For business IT applications, Lightsail runs Windows-based solutions in a secure, easily managed, and performant cloud environment. For Microsoft developers, Windows Server on Lightsail provides a flexible and agile development platform, integrated with .NET to help accelerate development cycles.",
            "platform": "WINDOWS",
            "productUrl": "https://aws.amazon.com/marketplace/pp/B00KQOWCAQ",
            "version": "2018.07.11",
            "licenseUrl": "https://d7umqicpi7263.cloudfront.net/eula/product/0be26530-fe62-4f93-91d1-96c810c19d42/4bedc10c-144d-40b4-98a1-373c3e82422c.txt",
            "versionCode": "1",
            "blueprintId": "windows_server_2012_2018_07_11",
            "minPower": 0,
            "type": "os",
            "isActive": true,
            "name": "Windows Server 2012 R2"
        },

※省略
```


## bundle_id
```
$ aws lightsail get-bundles
{
    "bundles": [
        {
            "supportedPlatforms": [
                "LINUX_UNIX"
            ],
            "name": "Nano",
            "power": 300,
            "price": 3.5,
            "ramSizeInGb": 0.5,
            "diskSizeInGb": 20,
            "transferPerMonthInGb": 1024,
            "cpuCount": 1,
            "instanceType": "nano",
            "isActive": true,
            "bundleId": "nano_2_0"
        },
        {
            "supportedPlatforms": [
                "LINUX_UNIX"
            ],
            "name": "Micro",
            "power": 500,
            "price": 5.0,
            "ramSizeInGb": 1.0,
            "diskSizeInGb": 40,
            "transferPerMonthInGb": 2048,
            "cpuCount": 1,
            "instanceType": "micro",
            "isActive": true,
            "bundleId": "micro_2_0"
        },
※省略
```

# jqを活用した絞り込み
上記だけでは何なので、jqを活用してちょっと便利にしてみました。

## 目的のBlueprintを検索する
例えば、WordPress用のBlueprintを検索したい場合は下記のように抽出できます。
DescriptionにWordPressという文字列（WとPは小文字を許容）を含むBlueprintのみを抽出します。

```
$ aws lightsail get-blueprints| jq '.blueprints[] | select (.description | test(".*[Ww]ord[Pp]ress.*"))'
{
  "group": "wordpress",
  "description": "WordPress powered by Bitnami and sold by BitRock Inc. is a pre-configured, ready to run image for running WordPress on Amazon EC2. WordPress is one of the world's most popular web publishing platforms for building blogs and websites. It can be customized via a wide selection of themes, extensions and plug-ins.",
  "platform": "LINUX_UNIX",
  "productUrl": "https://aws.amazon.com/marketplace/pp/B00NN8Y43U",
  "version": "4.9.6",
  "licenseUrl": "https://d7umqicpi7263.cloudfront.net/eula/product/7d426cb7-9522-4dd7-a56b-55dd8cc1c8d0/588fd495-6492-4610-b3e8-d15ce864454c.txt",
  "versionCode": "1",
  "blueprintId": "wordpress_4_9_6",
  "minPower": 0,
  "type": "app",
  "isActive": true,
  "name": "WordPress"
}
{
  "group": "plesk_ubuntu",
  "description": "Build, secure, and run websites and applications on Amazon Lightsail and AWS using the Hosting Stack powered by Plesk. This includes all your web-based server management and security tools, plus WordPress automation in a graphical user interface. It simplifies the work of web professionals and provides the scalability, security, and performance that your customers need.",
  "platform": "LINUX_UNIX",
  "productUrl": "https://aws.amazon.com/marketplace/pp/B077MJL7Z2",
  "version": "17.8.11",
  "licenseUrl": "https://d7umqicpi7263.cloudfront.net/eula/product/9e3e4089-d350-49f4-9988-c70d95c75c49/02d5b328-f4c7-4c30-8c08-63762ec65155.txt",
  "versionCode": "1",
  "blueprintId": "plesk_ubuntu_17_8_11_1",
  "minPower": 500,
  "type": "app",
  "isActive": true,
  "name": "Plesk Hosting Stack on Ubuntu"
}
```

## 費用が$5/month以下のBundleを検索する
```
$ aws lightsail get-bundles | jq '.bundles[] | select(.price <= 5.0)'
{
  "supportedPlatforms": [
    "LINUX_UNIX"
  ],
  "name": "Nano",
  "power": 300,
  "price": 3.5,
  "ramSizeInGb": 0.5,
  "diskSizeInGb": 20,
  "transferPerMonthInGb": 1024,
  "cpuCount": 1,
  "instanceType": "nano",
  "isActive": true,
  "bundleId": "nano_2_0"
}
{
  "supportedPlatforms": [
    "LINUX_UNIX"
  ],
  "name": "Micro",
  "power": 500,
  "price": 5,
  "ramSizeInGb": 1,
  "diskSizeInGb": 40,
  "transferPerMonthInGb": 2048,
  "cpuCount": 1,
  "instanceType": "micro",
  "isActive": true,
  "bundleId": "micro_2_0"
}
```