| name | description |
|---|---|
Serverless Framework GitHub Actions Deployment |
Set up GitHub Actions workflow for Serverless Framework or oss-serverless projects. Enables secure deployment using AWS OIDC authentication without storing IAM credentials locally. Supports multiple environments (dev/prod) with manual workflow dispatch. |
-
role: system content: |- You help add secure GitHub Actions deployment workflows to Serverless Framework (or oss-serverless) projects. The goal is to eliminate IAM user credentials from local machines by using OIDC-based AWS authentication.
- Analyze the project to detect configuration values
- Generate customized workflow based on detected values
- List required GitHub secrets specific to this project
- Provide setup instructions tailored to the project
Before generating the workflow, examine these files to detect configuration:
-
serverless.yml or serverless.ts:
provider.region→ AWS regionprovider.runtime→ Determine if Python setup is neededprovider.environment→ Global environment variables (apply to all functions)functions.<name>.environment→ Function-specific environment variablesstagesconfiguration → Available environments (dev/prod/staging)
-
package.json:
engines.node→ Node.js versionscripts.deploy→ Detect if usingsls,osls, orsst
-
Version manager files:
.nvmrcor.node-version→ Node.js version.tool-versions(asdf) → Node.js and Python versions.mise.tomlor.mise/config.toml(mise) → Node.js and Python versions
-
Git configuration:
- Check default branch name (
git symbolic-ref refs/remotes/origin/HEADor common patterns)
- Check default branch name (
-
runtime.txt or requirements.txt:
- Python version if present (fallback)
- Node.js version: Priority order:
- package.json
engines.node .tool-versions(asdf)nodejsentry.mise.tomlor.mise/config.tomlnodejsentry.nvmrcor.node-version- Default to '20'
- package.json
- Python setup: Include only if runtime starts with 'python' in serverless.yml
- Python version: Priority order:
- serverless.yml
provider.runtime(e.g., 'python3.12' → '3.12') .tool-versions(asdf)pythonentry.mise.tomlor.mise/config.tomlpythonentryruntime.txtorrequirements.txt- Default to '3.12'
- serverless.yml
- AWS region: Use from serverless.yml provider.region, or default to 'us-east-1'
- Deploy command: Check package.json scripts or dependencies for 'serverless', 'oss-serverless', or 'sst'
- Default branch: Detect from git, or use 'main' as default
- Environment variables: Extract from:
provider.environment(global)functions.<name>.environment(function-specific)- Identify variables using
${env:VAR_NAME}pattern - Only these variables need GitHub Secrets injection in workflow
- Stages: Extract from custom.stages or use [dev, prod] as default
If a value cannot be detected:
- Use sensible defaults (as listed above)
- Mark with comments in the generated YAML:
# TODO: Verify this value - Report to user which values are defaults vs detected:
Detected configuration: - Node.js version: 20 (default - not found in project) - AWS region: us-east-1 (from serverless.yml) - Ask for confirmation if critical values are missing (e.g., deploy command unclear)
-
role: system content: |-
This skill adds a GitHub Actions workflow that:
- Uses OIDC (OpenID Connect) for AWS authentication (no long-lived credentials)
- Supports multiple environments (dev/prod)
- Allows manual deployment via workflow_dispatch
- Injects environment-specific secrets at deploy time
Before implementation, analyze the project:
-
Detect Serverless configuration
- Read
serverless.ymlorserverless.ts - Identify deploy command from
package.jsonscripts/dependencies
- Read
-
Extract environment variables
- Parse
provider.environmentsection (global variables) - Parse each
functions.<name>.environmentsection (function-specific variables) - Collect unique variable names across all functions
- Identify variables that need GitHub Secrets injection:
- Variables with
${env:VAR_NAME}→ Need to be injected from GitHub Secrets - Variables with
${ssm:...}or${param:...}→ May not need injection (AWS-side resolution) - Static string values → No injection needed
- Variables with
- Only generate
env:section in workflow if there are variables requiring injection
- Parse
-
Determine runtime requirements
- Node.js version from
package.jsonengines or.nvmrc - Python version from
provider.runtimein serverless config - Check if Python setup step is needed
- Node.js version from
-
Detect AWS region and stages
- Region from
provider.region - Stages from
custom.stagesor default to [dev, prod]
- Region from
-
Check default branch
- Run
git symbolic-ref refs/remotes/origin/HEADor check common patterns
- Run
Create
.github/workflows/deploy.ymlbased on this template (customize as needed):name: Deploy on: workflow_dispatch: inputs: environment: description: 'Environment to deploy' required: true type: choice options: - dev - prod branch: description: 'Branch to deploy' required: false default: 'main' permissions: id-token: write contents: read jobs: deploy: runs-on: ubuntu-latest environment: ${{ inputs.environment }} steps: - uses: actions/checkout@v6 with: ref: ${{ inputs.branch || 'main' }} - uses: actions/setup-node@v6 with: node-version: '20' # Adjust based on project # Add if Python runtime is used - uses: actions/setup-python@v6 with: python-version: '3.12' # Adjust based on Lambda runtime - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v6.0.0 with: role-to-assume: ${{ secrets.AWS_ROLE_ARN }} aws-region: us-east-1 # Adjust based on project - name: Install dependencies run: npm install - name: Deploy env: # Only include if project uses ${env:VAR_NAME} in serverless.yml # Add project-specific secrets here based on detected ${env:} references # Example: # API_KEY: ${{ secrets.API_KEY }} # SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} run: npx sls deploy --stage ${{ inputs.environment }} # Or for oss-serverless: npx osls deploy --stage ${{ inputs.environment }}
Note: This is a template. All items marked with comments like
# Adjust based on projectmust be customized for your specific project.Adjust these elements:
- Default branch: Change
mastertomainif needed - Node.js version: Match project requirements
- Python setup: Remove if not using Python runtime
- AWS region: Set to project's target region
- Deploy command: Use
slsoroslsas appropriate - Environment variables:
- Only add
env:section if project uses${env:VAR_NAME}in serverless.yml - Extract variable names from
${env:XXX}patterns - Map each to
VAR_NAME: ${{ secrets.VAR_NAME }} - If no
${env:}references exist, omit the entireenv:section
- Only add
(This section is now covered in Post-Setup Instructions above)
- Serverless Framework:
npx sls deploy --stage ${{ inputs.environment }} - oss-serverless:
npx osls deploy --stage ${{ inputs.environment }} - SST:
npx sst deploy --stage ${{ inputs.environment }}
Node.js only:
- Remove Python setup step
Python only:
- Keep Python setup
- May still need Node.js for Serverless CLI
Multiple runtimes:
- Keep both setup steps
Add before deploy if needed:
- name: Build run: npm run build - name: Run tests run: npm test
- Never commit AWS credentials or tokens
- Use GitHub environment secrets for sensitive values
- OIDC roles should follow least-privilege principle
- Consider adding environment protection rules in GitHub
- Missing secrets: Deployment fails if secrets aren't configured in GitHub
- Wrong stage name: Ensure
--stagematches serverless.yml configuration - Insufficient IAM permissions: OIDC role needs CloudFormation, Lambda, S3, etc.
- Branch protection: Ensure workflow has permission to read protected branches
After implementation:
- Go to Actions tab in GitHub
- Select "Deploy" workflow
- Click "Run workflow"
- Choose environment and branch
- Verify deployment succeeds
When user requests this skill:
- Analyze the project first - Read serverless.yml, package.json, etc.
- Report detected values - Show what you found:
Detected configuration: - Node.js version: 20 (from package.json) - Python runtime: 3.12 (from serverless.yml provider.runtime) - AWS region: us-east-1 (from serverless.yml) - Deploy command: npx osls deploy (from package.json) - Default branch: main (from git) - Stages: dev, prod (from serverless.yml) - Environment variables requiring injection: API_KEY, SERVICE_URL, AUTH_TOKEN, ... - Generate customized
.github/workflows/deploy.ymlwith detected values - Provide post-setup instructions (see below)
After generating the workflow file, provide these instructions to the user:
For each environment (dev, prod, etc.), run:
# Create environment (if not exists) gh api repos/{owner}/{repo}/environments/{environment_name} -X PUT # Set secrets for the environment gh secret set AWS_ROLE_ARN --env {environment_name} # Paste the IAM Role ARN when prompted # Set each environment variable detected from serverless.yml gh secret set VARIABLE_NAME --env {environment_name} # Repeat for each variable
Example for this project:
# For prod environment gh api repos/{owner}/{repo}/environments/prod -X PUT gh secret set AWS_ROLE_ARN --env prod gh secret set API_KEY --env prod gh secret set SERVICE_URL --env prod gh secret set AUTH_TOKEN --env prod # ... (list all detected variables)
The OIDC IAM Role must trust this specific repository. Update the role's trust policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::{ACCOUNT_ID}:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" }, "StringLike": { "token.actions.githubusercontent.com:sub": "repo:{owner}/{repo}:*" } } } ] }For this project, add:
"token.actions.githubusercontent.com:sub": "repo:{owner}/{repo}:*"Ensure the IAM Role has sufficient permissions for Serverless deployment:
- CloudFormation (CreateStack, UpdateStack, DeleteStack, DescribeStacks, etc.)
- Lambda (CreateFunction, UpdateFunctionCode, etc.)
- IAM (CreateRole, AttachRolePolicy - for Lambda execution roles)
- S3 (CreateBucket, PutObject - for deployment artifacts)
- API Gateway (if used)
- CloudWatch Logs (if used)
- Other services used by your functions
Consider adding protection rules in GitHub:
# Require approval for production deployments gh api repos/{owner}/{repo}/environments/prod -X PUT -f wait_timer=0 -f prevent_self_review=true- Go to Actions tab:
https://github.com/{owner}/{repo}/actions - Select "Deploy" workflow
- Click "Run workflow"
- Choose environment and branch
- Monitor the deployment
If the AWS account doesn't have GitHub OIDC provider yet:
aws iam create-open-id-connect-provider \ --url https://token.actions.githubusercontent.com \ --client-id-list sts.amazonaws.com \ --thumbprint-list xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Or use AWS Console:
- IAM → Identity providers → Add provider
- Provider type: OpenID Connect
- Provider URL:
https://token.actions.githubusercontent.com - Audience:
sts.amazonaws.com
実際のプロジェクトで Kiro CLI から実行してみた結果が以下。
プロジェクト分析が完了しました。GitHub Actionsワークフローを作成します。
検出された設定
Node.js version: 20 (デフォルト - package.jsonに指定なし)
Python runtime: 3.12 (serverless.ymlとasdfから検出)
AWS region: ap-northeast-1 (serverless.ymlから検出)
Deploy command: npx sls deploy (serverless使用)
Default branch: master (gitから検出)
Repository: my-org/my-repo
Stages: dev, prod (デフォルト)
環境変数: serverless.ymlでSSM Parameter Storeを使用しているため、${env:}パターンは不使用 → workflow内での環境変数注入は不要
I will run the following command: mkdir -p .github/workflows (using tool: shell)
Purpose: .github/workflowsディレクトリを作成
Completed in 0.32s
I'll create the following file: /home/me/my-repo/.github/workflows/deploy.yml (using tool: write)
Purpose: GitHub Actions deployワークフローを作成
...(中略)...
✅ GitHub Actionsワークフローを作成しました: .github/workflows/deploy.yml
セットアップ手順
1. GitHub環境とシークレットを作成
各環境(dev, prod)に対して実行:
devも同様に:
gh api repos/my-org/my-repo/environments/dev -X PUT gh secret set AWS_ROLE_ARN --env dev2. IAM RoleのTrust Policyを更新
OIDC IAM Roleの信頼ポリシーに以下を追加:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::{ACCOUNT_ID}:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" }, "StringLike": { "token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:*" } } } ] }3. IAM Roleの権限を確認
以下の権限が必要:
4. (初回のみ) GitHub OIDC Providerを作成
AWSアカウントにまだない場合:
5. ワークフローをテスト
注意: このプロジェクトはSSM Parameter Storeから認証情報を取得するため、ワークフロー内で環境変数を注入する必要はありません。