Skip to content

いけたー

いけたー #16

Workflow file for this run

name: Deploy-Lambda-Python
on:
push:
branches:
- "main"
pull_request:
paths:
- "**/*.py"
- "**/deploy_lambda.yml"
permissions:
id-token: write
contents: read
defaults:
run:
working-directory: "hello_lambda"
env:
PYTHON_VERSION: 3.13
function-name: hello_lambda_actions
lambda-role-arn: ${{ secrets.LAMBDA_ROLE_ARN }}
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Build
run: pip install -r requirements.txt
- name: Load environment variables from .env file
id: load-env
run: |
if [ -f .env ]; then
echo "Loading environment variables from .env file"
# .envファイルから環境変数を読み取りJSON形式に変換
env_json="{"
first=true
while IFS='=' read -r key value || [ -n "$key" ]; do
# コメント行と空行をスキップ
if [[ "$key" =~ ^#.*$ ]] || [[ -z "$key" ]]; then
continue
fi
# 値からクォートを除去
value=$(echo "$value" | sed 's/^"\(.*\)"$/\1/' | sed "s/^'\(.*\)'$/\1/")
# JSONにキー・値のペアを追加
if [ "$first" = true ]; then
env_json="$env_json\"$key\":\"$value\""
first=false
else
env_json="$env_json,\"$key\":\"$value\""
fi
done < .env
env_json="$env_json}"
echo "Loaded environment variables: $env_json"
echo "env-vars=$env_json" >> $GITHUB_OUTPUT
else
echo "No .env file found, using default environment variables"
default_env='{"ENVIRONMENT":"production","LOG_LEVEL":"info","PYTHON_VERSION":"'"${{ env.PYTHON_VERSION }}"'"}'
echo "Default environment variables: $default_env"
echo "env-vars=$default_env" >> $GITHUB_OUTPUT
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1
- name: Deploy Lambda
uses: aws-actions/aws-lambda-deploy@v1.0.1
with:
function-name: ${{ env.function-name }}
code-artifacts-dir: ./hello_lambda
handler: app.lambda_handler
runtime: python${{ env.PYTHON_VERSION }}
dry-run: false
environment: ${{ steps.load-env.outputs.env-vars }}