0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【基礎】GitHub Actions を利用して AWS SAM のデプロイ環境を構築する

Last updated at Posted at 2025-03-27

概要

  • 自分のPCでデプロイすると、スペックが低いためかビルド/デプロイにめちゃくちゃ時間がかかる
  • ワンちゃんGitHubActionsのほうが性能が高い説があるので試してみる

方法

ひとまずこれを参考にしてやってみる
なるべく元サイトと同じような形でやろうと思います

ID プロバイダの作成

image.png

公式にもこう書いてありますね

1.以下のURLの場所に遷移します。

2.プロバイダを追加を選択します
image.png

3.次のように入力します

image.png

4.ARNが必要なので保存しておきます
image.png

5.IAMロールを作ります
以下は公式サイトをそのまま持ってきました。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
-                "Federated": "arn:aws:iam::123456123456:oidc-provider/token.actions.githubusercontent.com"
+                "Federated": "arn:aws:iam::自分のやつ:oidc-provider/token.actions.githubusercontent.com"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
-                    "token.actions.githubusercontent.com:sub": "repo:octo-org/octo-repo:*"
+                    "token.actions.githubusercontent.com:sub": "repo:アカウント名/対象レポジトリ:*" 
                },
                "StringEquals": {
                    "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
                }
            }
        }
    ]
}

とか思っていたら、GUIでも可能見たいです
image.png

下に、組織等を入れる場所がある感じです。

今回はひとまずこんな感じにしました。
IAMがフルなのは怖いので後で直す予定です
image.png

このあと、CloudFrontなどほかに必要な奴めちゃ追加しました。
後からインラインポリシー等で調整できるので、最初は動かない前提でやるのがよさそう

ワークフローを設定する

ひとまずお試しなので、参考サイトまんまです。

.github/workflows/deploy.yaml
name: Deploy-AWS-SAM-Application

on:
 push:
   branches:
     - 'develop'

env:
 TEMPLATE_FILE: template.yaml
 SAM_CLI_TELEMETRY: 0

permissions:
 id-token: write
 contents: read

jobs:
 deploy:
   runs-on: ubuntu-22.04
   permissions:
     id-token: write
     contents: read
   steps:
     - uses: actions/checkout@v3
     - uses: actions/setup-python@v3
     - uses: aws-actions/setup-sam@v2
       with:
         use-installer: true
     - uses: aws-actions/configure-aws-credentials@v4
       with:
         role-to-assume: arn:aws:iam::194722430871:role/github-actions-role
         aws-region: ap-northeast-1
         role-session-name: SamDeploy
     - run: sam build
     - run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset

NextJs on lambda 試行錯誤

独自にカスタマイズする中で苦労した部分について

Nextのほうは記載次第つい

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?