

# GitHub Actions を使用した Lambda 関数のデプロイ
<a name="deploying-github-actions"></a>

[GitHub Actions](https://github.com/features/actions) を使用することで、リポジトリにコードや設定の変更をプッシュするときに Lambda 関数を自動でデプロイできます。[Deploy Lambda Function](https://github.com/aws-actions/aws-lambda-deploy) アクションは、手動でのデプロイステップの複雑性を解消する宣言型のシンプルな YAML インターフェイスを提供します。

## ワークフローの例
<a name="deploying-github-actions-example"></a>

自動化された Lambda 関数デプロイを設定するには、リポジトリの `.github/workflows/` ディレクトリにワークフローファイルを作成します。

**Example Lambda デプロイ用の GitHub Actions ワークフロー**  

```
name: Deploy AWS Lambda

on:
  push:
    branches: 
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      id-token: write # Required for OIDC authentication
      contents: read  # Required to check out the repository
    steps:
      - uses: actions/checkout@v4
      
      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123456789012:role/GitHubActionRole
          aws-region: us-east-1
      
      - name: Deploy Lambda Function
        uses: aws-actions/aws-lambda-deploy@v1
        with:
          function-name: my-lambda-function
          code-artifacts-dir: ./dist
```

このワークフローは、`main` ブランチに変更をプッシュするときに実行されます。リポジトリを調べ、OpenID Connect (OIDC) を使用して AWS 認証情報を設定し、`./dist` ディレクトリ内のコードを使用して関数をデプロイします。

関数設定の更新、S3 バケット経由のデプロイ、ドライラン検証などのその他の例については、「[Deploy Lambda Function README](https://github.com/aws-actions/aws-lambda-deploy)」を参照してください。

## その他のリソース
<a name="deploying-github-actions-resources"></a>
+ [Configure AWS Credentials GitHub Action](https://github.com/aws-actions/configure-aws-credentials)
+ [AWS での OpenID Connect の構成](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)