cicd: 로그 확인 #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Deploy to AWS Lambda | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Parse secrets | |
| run: | | |
| echo '${{ secrets.LAMBDA_ENV_JSON }}' | jq -r 'to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_ENV | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Build, tag, and push image to Amazon ECR | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }} | |
| IMAGE_TAG: latest | |
| run: | | |
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
| - name: Update Lambda function | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ env.ECR_REPOSITORY }} | |
| IMAGE_TAG: latest | |
| LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION_NAME }} | |
| run: | | |
| aws lambda update-function-code \ | |
| --function-name $LAMBDA_FUNCTION_NAME \ | |
| --image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ | |
| --region ${{ env.AWS_REGION }} | |
| # 함수 업데이트가 완료될 때까지 대기 | |
| aws lambda wait function-updated \ | |
| --function-name $LAMBDA_FUNCTION_NAME \ | |
| --region $AWS_REGION | |
| - name: Update Lambda environment variables | |
| env: | |
| LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION_NAME }} | |
| run: | | |
| ENV_STRING=$(cat $GITHUB_ENV | paste -sd "," -) # 라인들을 , 로 합치기 | |
| cat ENV_STRING | |
| aws lambda update-function-configuration \ | |
| --function-name $LAMBDA_FUNCTION_NAME \ | |
| --environment Variables={$ENV_STRING} \ | |
| --region ${{ env.AWS_REGION }} |