More Related Content
Similar to AWS App RunnerでASP.NET Core Webアプリケーションを動かしてみた (20)
More from Ken'ichirou Kimura (20)
AWS App RunnerでASP.NET Core Webアプリケーションを動かしてみた
- 1. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
AWS App RunnerでC#のアプリを動かしてみた
2021年7月3日
木村健一郎
(@show_m001)
- 2. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
名前:木村健一郎(しょーちゃん)
所属:株式会社オルターブース
JAWS-UG福岡
SORACOM UG九州
娘ちゃんのパパ(3歳11ヶ月)
お仕事:テクニカルアーキテクト
好きなAWSサービス: Lambda
好きなSORACOMサービス:Arc,Funk
- 3. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
Webアプリ、どこで動かしてます?
WebアプリをAWSで動かす場合・・・
• EC2
IaaSのメンテしたくない
• ElasticBeanstalk
ちょっと楽になったけどお手軽とまでは・・
• ECS/Fargate
いきなりコンテナってちょっと一足飛びな感じ
• EKS
いや、そこまでいらん
もっとお手軽なPaaSがほしい!
(*)個人の感想です
- 4. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
Webアプリ実行環境のPaaSといえば
・Azure App Service(Web Apps)
・Web Apps超楽ちん
・PaaSなのでコード送り込むだけ
・BGデプロイとかCI/CDパイプラインもポチポチで
いける
・AzureAD/AzureAD B2Cを使ったアクセス制御も
簡単(Easy auth)
・開発用のフリープランがある
- 6. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
AWS App Runnerとは
皆さんが沢山話されてると思うので省略
いつも業務でよく使う C# + ASP.NET Coreのアプリを動かしてみました
- 7. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
やってみた(1)
VisualStudio 2019 + AWS Toolkit for VisualStudioでやってみます。
テンプレートから ASP.NET Core Webアプリを作ります。
- 9. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
やってみた(3)
テンプレートのアプリを起動するとこんな画面になりますが、環境変数を読み
込んで表示するという動作を追加しておきます。
ApplicationOptions:ApplicationNameという設定を渡すようにします。appsettings.jsonだ
とこんな感じですね
{
“ApplicationOptions”: {
“ApplicationName”: “appname from appsettings.json”
}
}
- 10. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
やってみた(4)
コンテナイメージをECRにプッシュします
ソリューションを右クリックすると「Publish Container to AWS」があります
- 11. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
やってみた(5)
Publishはこんな画面で行います
必要事項を入力したら「Publish」を押すだけです
- 12. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
ちなみにDeployment Targetで選択できるのはこんな感じ。
• Service on an ECS Cluster
• Run Task on an ECS Cluster
• Schduled Task on an ECS Clusnter
• Push only the Docker image to Amazon Elastic Container Registry
ECS関連を選ぶともろもろ設定してデプロイできるので、いずれここにApp
Runnerも来るのかなーと期待してます。
- 13. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
やってみた(7)
App Runnerを作ります
環境変数を足すのを忘れない。「:」は「__」(アンダーバー2つ)にします。
これはElasticBeanstalkでも同じですね。
- 15. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
環境変数を変えてみよう
コンソールから環境変数を変更できます。
保存するとサービスが再デプロイされます。
- 17. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
【参考】CLIから環境変数を変えてみよう(1)
2021/6/5に試した際は、コンソールからできなかったのでCLIからやってみま
した。
まずは現在の設定を取得します。
$aws apprunner describe-service --service-arn $APPARN
{
"Service": {
"ServiceName": "WebApplicationForAppRunner",
"ServiceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
.....
"SourceConfiguration": {
"ImageRepository": {
"ImageIdentifier": "xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/webapplicationforapprunner:latest",
"ImageConfiguration": {
"RuntimeEnvironmentVariables": {
"ApplicationOptions__ApplicationName": "appname from environment“
},
"Port": "80“
},
"ImageRepositoryType": "ECR" },
.......
}
- 18. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
【参考】CLIから環境変数を変えてみよう(2)
必要な部分だけ書き換えます。
{
"SourceConfiguration": {
"ImageRepository": {
"ImageIdentifier": "xxxxxxxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/apprunnertestwebapplication:latest",
"ImageConfiguration": {
"RuntimeEnvironmentVariables": {
"ApplicationOptions__ApplicationName": "appname from environment2" }
},
"ImageRepositoryType": "ECR" }
}
}
SourceConfiguration部分を持ってきて変更し、ファイルに保存します。
- 19. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
環境変数を変えてみよう(3)
ファイルに保存し、CLIから送り込みます
$aws apprunner update-service --service-arn $APPARN --cli-input-json file://apprunner-json_modify.json
{
"Service": {
"ServiceName": "WebApplicationForAppRunner",
"ServiceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
.....
"SourceConfiguration": {
"ImageRepository": {
"ImageIdentifier": "xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/webapplicationforapprunner:latest",
"ImageConfiguration": {
"RuntimeEnvironmentVariables": {
"ApplicationOptions__ApplicationName": "appname from environment2“
},
"Port": "80“
},
"ImageRepositoryType": "ECR" },
.......
}
- 20. Copyright © 2015-2021 ALTERBOOTH inc. All Rights Reserved.
まとめ
・AppRunner超優秀
お手軽にWebアプリ動かせるPaaSは嬉しい
・ASP.NET Coreのアプリも普通に動きます
まぁコンテナだし(身も蓋もない)
・ソースからのCI/CDに他の言語も欲しい
apprunner.yamlで頑張ったらどうにかなる?(未検証)
・ちょっとお金かかる
テスト・開発用の安いインスタンスが欲しい
・詳細はブログに書いてます
https://aadojo.alterbooth.com/entry/2021/06/07/094030