LoginSignup
3
0

More than 5 years have passed since last update.

AWS CodeDeployで最新のデプロイ済みの成果物を取得する

Posted at

モチベーション

現在の最新のデプロイ済みの成果物の状態を見て処理を分ける必要があり、awscliでサクッと取得できるのか調べたところ、どうやら1発では引けませんでした。
なのでshellにしました。

スクリプト

#!/bin/bash
APP_NAME=<set application name>
DEPLOYMENT_GROUP=<set deployment group>

DEPLOY_ID=$(aws deploy list-deployments --application-name ${APP_NAME} --deployment-group-name ${DEPLOYMENT_GROUP} --include-only-statuses Succeeded --max-items 1 --query 'deployments[0]' --output text | head -n1)

BUCKET=$(aws deploy get-deployment --deployment-id ${DEPLOY_ID} --query 'deploymentInfo.revision.s3Location.bucket' --output text)
KEY=$(aws deploy get-deployment --deployment-id ${DEPLOY_ID} --query 'deploymentInfo.revision.s3Location.key' --output text)

aws s3 cp s3://${BUCKET}/${KEY} .

s3のバケットとキーをそれぞれ取得するためにapiを2度呼んでるのはjqに依存したくなかったからです。sedも環境に依存するので説明を省略するためにやりませんでした。
1発で情報を取得するなら以下に置き換えれば可能です。

aws deploy get-deployment --deployment-id ${DEPLOY_ID} --query 'deploymentInfo.revision.s3Location' --output json

最後に

同じようなシチュエーションで誰かの役に立ったら幸いです。
また、もっとスマートにいけるよ!という方は教えてください :smile:

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0