LoginSignup
0
0

More than 5 years have passed since last update.

[JAWS-UG CLI] CodeDeploy #2 アプリケーションの確認 (CodePipelineでデプロイした場合)

Posted at

AWS CLIを利用して、CodePipelineでデプロイしたCodeDeploy上のアプリケーションを確認します。

前提条件

CodeDeployへの権限

Code Deployに対してフル権限があること。

AWS CLIのバージョン

以下のバージョンで動作確認済

  • AWS CLI 1.11.2
コマンド
aws --version
結果(例)
         aws-cli/1.11.2 Python/2.7.11 Darwin/15.6.0 botocore/1.4.60

バージョンが古い場合は最新版に更新しましょう。

コマンド
sudo -H pip install -U awscli

0. 準備

0.1. 変数の確認

プロファイルが想定のものになっていることを確認します。

コマンド
aws configure list
結果(例)
               Name                    Value             Type    Location
               ----                    -----             ----    --------
            profile         iamFull-prjZ-mbp13        env    AWS_DEFAULT_PROFILE
         access_key     ****************XXXX shared-credentials-file
         secret_key     ****************XXXX shared-credentials-file
             region                         us-east-1  env    AWS_DEFAULT_REGION

AssumeRoleを利用している場合はprofileが ''と表示されます。それ以外のときにprofileが '' と表示される場合は、以下を実行してください。

変数の設定
export AWS_DEFAULT_PROFILE=<IAMユーザ名>

0.2. アプリケーション名の指定

変数の設定
CODED_APP_NAME="handson-app-20161010"

0.3. デプロイメントグループ名の指定

変数の設定
CODED_DEPLOY_GROUP_NAME="handson-app-20161010-deployment-group"

1. 事前作業

デプロイメントの確認

コマンド
aws deploy list-deployments 
結果(例)
      {
        "deployments": [
          "d-xxxxxxxxx"
        ]
      }
変数の設定
CODED_DEPLOY_ID='<デプロイメントID>'
コマンド
aws deploy get-deployment \
        --deployment-id ${CODED_DEPLOY_ID}
結果(例)
      {
        "deploymentInfo": {
          "applicationName": "handson-app-20161010",
          "status": "Succeeded",
          "deploymentOverview": {
              "Failed": 0,
              "InProgress": 0,
              "Skipped": 0,
              "Succeeded": 1,
              "Pending": 0
          },
          "deploymentConfigName": "CodeDeployDefault.OneAtATimeCodeDeployDefault.OneAtATime",
          "creator": "user",
          "deploymentId": "d-xxxxxxxxx",
          "ignoreApplicationStopFailures": false,
          "autoRollbackConfiguration": {
              "enabled": false
          },
          "updateOutdatedInstancesOnly": false,
          "deploymentGroupName": "handson-app-20161010-deployment-group",
          "createTime": 1234567890.123,
          "completeTime": 1234567890.123,
          "revision": {
              "revisionType": "S3",
              "s3Location": {
                  "bundleType": "zip",
                  "eTag": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-x",
                  "bucket": "codepipeline-us-east-1-xxxxxxxxxxxx",
                  "key": "MyFirstPipeline/MyApp/xxxxxxx"
              }
          }
        }
      }

2. デプロイメントインスタンスの確認

2.1. インスタンス一覧の確認

コマンド
aws deploy list-deployment-instances \
        --deployment-id ${CODED_DEPLOY_ID}
結果(例)
      {
        "instancesList": [
          "i-xxxxxxxx"
        ]
      }

2.2. インスタンスの指定

変数の設定
EC2_INSTANCE_ID='<インスタンスID>'

2.3. インスタンスの確認

コマンド
aws deploy get-deployment-instance \
        --deployment-id ${CODED_DEPLOY_ID} \
        --instance-id ${EC2_INSTANCE_ID}
結果(例)
      {
        "instanceSummary": {
          "instanceId": "arn:aws:ec2:us-east-1:XXXXXXXXXXXX:instance/i-72729742",
          "status": "Succeeded",
          "deploymentId": "d-xxxxxxxxx",
          "lastUpdatedAt": 1234567890.123,
          "lifecycleEvents": [
              {
                  "endTime": 1234567890.12,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567890.123,
                  "lifecycleEventName": "ApplicationStop"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567890.123,
                  "lifecycleEventName": "DownloadBundle"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567890.123,
                  "lifecycleEventName": "BeforeInstall"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567836.286,
                  "lifecycleEventName": "Install"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567837.518,
                  "lifecycleEventName": "AfterInstall"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567839.023,
                  "lifecycleEventName": "ApplicationStart"
              },
              {
                  "endTime": 1234567890.123,
                  "status": "Succeeded",
                  "diagnostics": {
                      "errorCode": "Success",
                      "scriptName": "",
                      "logTail": "",
                      "message": "Succeeded"
                  },
                  "startTime": 1234567890.123,
                  "lifecycleEventName": "ValidateService"
              }
          ]
        }
      }

3. アプリのリビジョン設定の確認

コマンド
aws deploy list-application-revisions \
        --application-name ${CODED_APP_NAME}
結果(例)
      {
        "revisions": [
          {
              "revisionType": "S3",
              "s3Location": {
                  "bundleType": "zip",
                  "eTag": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-x",
                  "bucket": "codepipeline-us-east-1-xxxxxxxxxxxx",
                  "key": "MyFirstPipeline/MyApp/babsqoL"
              }
          }
        ]
      }
コマンド
CODED_LOCATION_BUCKET=$( \
        aws deploy list-application-revisions \
          --application-name ${CODED_APP_NAME} \
          --query "revisions[?revisionType == \`S3\`].s3Location.bucket" \
          --output text \
) \
        && echo ${CODED_LOCATION_BUCKET}
結果(例)
      codepipeline-us-east-1-123456789012
コマンド
CODED_LOCATION_BUNDLETYPE=$( \
        aws deploy list-application-revisions \
          --application-name ${CODED_APP_NAME} \
          --query "revisions[?revisionType == \`S3\`].s3Location.bundleType" \
          --output text \
) \
        && echo ${CODED_LOCATION_BUNDLETYPE}
結果(例)
      zip
コマンド
CODED_LOCATION_ETAG=$( \
        aws deploy list-application-revisions \
          --application-name ${CODED_APP_NAME} \
          --query "revisions[?revisionType == \`S3\`].s3Location.eTag" \
          --output text \
) \
        && echo ${CODED_LOCATION_ETAG}
結果(例)
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-x
コマンド
CODED_LOCATION_KEY=$( \
        aws deploy list-application-revisions \
          --application-name ${CODED_APP_NAME} \
          --query "revisions[?revisionType == \`S3\`].s3Location.key" \
          --output text \
) \
        && echo ${CODED_LOCATION_KEY}
結果(例)
      handson-pipeline-20161010/MyApp/xxxxxxx
変数の設定
STR_CODED_APP_REVISION="bucket=${CODED_LOCATION_BUCKET},bundleType=${CODED_LOCATION_BUNDLETYPE},eTag=${CODED_LOCATION_ETAG},key=${CODED_LOCATION_KEY}" \
        && echo ${STR_CODED_APP_REVISION}
コマンド
aws deploy get-application-revision \
        --application-name ${CODED_APP_NAME} \
        --s3-location ${STR_CODED_APP_REVISION}
結果(例)
      {
        "applicationName": "handson-app-20161010",
        "revisionInfo": {
          "lastUsedTime": 1234567890.123,
          "firstUsedTime": 1234567890.123,
          "registerTime": 1234567890.123,
          "description": "Application revision registered by Deployment ID: d-xxxxxxxxx",
          "deploymentGroups": [
              "handson-app-20161010-deployment-group"
          ]
        },
        "revision": {
          "revisionType": "S3",
          "s3Location": {
              "bundleType": "zip",
              "eTag": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-x",
              "bucket": "codepipeline-us-east-1-xxxxxxxxxxxx",
              "key": "MyFirstPipeline/MyApp/xxxxxxx"
          }
        }
      }

9. 事後作業

完了

0
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
0
0