📝
Elastic Beanstalk の環境に AWS CLI でアプリケーションをデプロイしてみた
Setting configuration options after environment creation - AWS Elastic Beanstalk
上記ドキュメントの手順通りです。
前提
- コンソール上から Node.js のサンプルアプリケーションで環境を作成済み
- AWS CLI の実行環境は CloudShell
サンプルアプリの編集
Tutorials and samples - AWS Elastic Beanstalk
上記ドキュメントから nodejs.zip をダウンロードします。
index.html の h1 タグを書き換えます。
nodejs/index.html
<h1>Updated</h1>
再度ファイル群を zip ファイル化して CloudShell にアップロードします。
環境へのデプロイ
コンソールから Elastic Beanstalk 環境を作成したため、Elastic Beanstalk 用の S3 バケットを作成する create-storage-location コマンドの実行はスキップします。
s3 cp コマンドで CloudShell から S3 バケットにソースバンドルの zip ファイルをアップロードします。
$ aws s3 cp nodejs.zip s3://elasticbeanstalk-ap-northeast-1-012345678901/my-app/nodejs.zip
upload: ./nodejs.zip to s3://elasticbeanstalk-ap-northeast-1-012345678901/my-app/nodejs.zip
create-application-version コマンドでアプリケーションバージョンを発行します。
$ aws elasticbeanstalk create-application-version \
--application-name test \
--version-label v3 \
--description MyAppv2 \
--source-bundle S3Bucket="elasticbeanstalk-ap-northeast-1-012345678901",S3Key="my-app/nodejs.zip"
{
"ApplicationVersion": {
"ApplicationVersionArn": "arn:aws:elasticbeanstalk:ap-northeast-1:012345678901:applicationversion/test/v2",
"ApplicationName": "test",
"Description": "MyAppv2",
"VersionLabel": "v2",
"SourceBundle": {
"S3Bucket": "elasticbeanstalk-ap-northeast-1-012345678901",
"S3Key": "my-app/nodejs.zip"
},
"DateCreated": "2025-04-12T10:03:26.962000+00:00",
"DateUpdated": "2025-04-12T10:03:26.962000+00:00",
"Status": "UNPROCESSED"
}
}
update-environment コマンドで環境を更新します。
$ aws elasticbeanstalk update-environment \
--environment-name Test-env \
--version-label v2
{
"EnvironmentName": "Test-env",
"EnvironmentId": "e-vvncneem9i",
"ApplicationName": "test",
"VersionLabel": "v2",
"SolutionStackName": "64bit Amazon Linux 2023 v6.5.0 running Node.js 22",
"PlatformArn": "arn:aws:elasticbeanstalk:ap-northeast-1::platform/Node.js 22 running on 64bit Amazon Linux 2023/6.5.0",
"EndpointURL": "54.238.217.67",
"CNAME": "Test-env.eba-tzmmkfmy.ap-northeast-1.elasticbeanstalk.com",
"DateCreated": "2025-04-12T09:44:20.164000+00:00",
"DateUpdated": "2025-04-12T10:05:01.847000+00:00",
"Status": "Updating",
"AbortableOperationInProgress": true,
"Health": "Grey",
"Tier": {
"Name": "WebServer",
"Type": "Standard",
"Version": "1.0"
},
"EnvironmentArn": "arn:aws:elasticbeanstalk:ap-northeast-1:012345678901:environment/test/Test-env"
}
環境更新完了後に Elastic Beanstalk のドメインにアクセスして Updated と表示されればデプロイ完了です。

補足
今回使用した AWS CLI コマンドは SDK でも提供されているため、SDK による自動化もできると思います。
- PutObject - Amazon Simple Storage Service
- CreateStorageLocation - AWS Elastic Beanstalk
- CreateApplicationVersion - AWS Elastic Beanstalk
- UpdateEnvironment - AWS Elastic Beanstalk
まとめ
今回は Elastic Beanstalk の環境に AWS CLI でアプリケーションをデプロイしてみました。
どなたかの参考になれば幸いです。
参考資料
- Setting configuration options after environment creation - AWS Elastic Beanstalk
- Tutorials and samples - AWS Elastic Beanstalk
- PutObject - Amazon Simple Storage Service
- CreateStorageLocation - AWS Elastic Beanstalk
- CreateApplicationVersion - AWS Elastic Beanstalk
- UpdateEnvironment - AWS Elastic Beanstalk
Discussion