sorta kinda...

主にAWS関連ですが、これに限らずいろいろ勉強したことや思ったことを書いていきます。

新しい Windows Server AMI のリリース通知を受け取ろう

ナスです。

仕事でいろいろ調べてたら、新しい Windows Server AMI がリリースされたら通知してくれる SNS があることを知りました。
docs.aws.amazon.com

どんなもんか知りたくなったので試してみました。

 

サブスクリプションを作成するだけ

手順は簡単で、上のリンクのまんまです。せっかくなので aws cli でやってみます。

aws --region us-east-1 sns subscribe --topic-arn arn:aws:sns:us-east-1:801119661308:ec2-windows-ami-update --protocol email --notification-endpoint xxx@domain.com
{
    "SubscriptionArn": "pending confirmation"
}

こんな感じで実行すると、一番後ろで指定したメールアドレスに確認メールが飛んできます。メール本文にある Confirm subscription のリンクをクリックすれば OK です。これで新しい Windows Server AMI がリリースされたらメールが飛んでくるようになります。

 

どんな内容の通知がくるのか?

サブスクリプション作成した翌日に奇跡的に通知が来たので、その内容を貼ります。

A new version of Amazon Machine Images has been released. Previous versions of Amazon published Windows AMIs 2018.02.30 and older will be deprecated on Tuesday, May 1st, at 10AM Pacific.
Please use this time to update any dependencies such as CloudFormation or Autoscaling groups.
 
EC2 Quickstart, AWS MarketPlace and CloudFormation templates will be updated over the next couple days.
 
New AMIs are dated 2018.04.11.
Search for this using the AWS Console, PowerShell Get-EC2ImageByName or using Powershell Get-SSMParametersByPath -Path "/aws/service/ami-windows-latest"
 
Changes:
- Microsoft Security Updates current to April 10th 2018
- Amazon SSM Agent v2.2.392.0
- Amazon EC2Config v4.9.2586
- AWS Tools for Windows PowerShell v3.3.256.0
- AWS CloudFormation v1.4.30
- Serial INF and Intel Chipset INF configurations included to support new EC2 instance types
- SQL Server 2017 AMIs updated to CU5
- SQL Server 2016 SP1 AMIs updated to CU8
 
Important:
Microsoft ended mainstream support for Windows Server 2016 Datacenter and Standard editions for Nano Server installation options as of 4/10/2018. (See the Microsoft Support Lifecycle page for more details: https://support.microsoft.com/en-us/lifecycle/search?alpha=nano)
A final update for Windows_Server-2016-English-Nano-Base AMI is in the April Windows AMI release. Access to all public versions of Windows_Server-2016-English-Nano-Base will be removed in September 2018.
Additional information about Nano Server lifecycle including details on launching Nano Server as a Container can be found here: https://docs.microsoft.com/en-us/windows-server/get-started/nano-in-semi-annual-channel
以下省略…

 

通知がいらなくなったら

サブスクリプションの解除をすれば OK です。サブスクリプション ARN を指定しないといけないので、こんな感じで ARN を確認します。

aws sns list-subscriptions --region us-east-1 | jq '.Subscriptions[] | select(.TopicArn=="arn:aws:sns:us-east-1:801119661308:ec2-windows-ami-update")'
{
  "SubscriptionArn": "arn:aws:sns:us-east-1:801119661308:ec2-windows-ami-update:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "Protocol": "email",
  "TopicArn": "arn:aws:sns:us-east-1:801119661308:ec2-windows-ami-update",
  "Endpoint": "xxx@domain.com",
  "Owner": "123456789012"
}

あとは確認した ARN を使って解除するコマンドを実行するだけです。↓は、ARN の確認と同時にサブスクリプション解除するワンライナーです。

ARN=`aws sns list-subscriptions --region us-east-1 | jq -r '.Subscriptions[] | select(.TopicArn=="arn:aws:sns:us-east-1:801119661308:ec2-windows-ami-update") | .SubscriptionArn'` && aws --region us-east-1 sns unsubscribe --subscription-arn $ARN

 

むちゃくちゃ簡単ですね。SNS での通知なので、メールじゃなくて slack に通知したり、SNS をトリガーにして lambda で何か処理したり、といったこともできそうです。