fix: probel #18
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: Deploy Lambda Service | |
| on: | |
| push: | |
| branches: [ master, main ] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| deployments: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ vars.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| # Set ECR image URI as environment variables | |
| - name: Set ECR image URIs | |
| id: set-image-uris | |
| run: | | |
| ECR_REGISTRY="${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com" | |
| ECR_REPOSITORY="${{ vars.ECR_REPOSITORY }}" | |
| IMAGE_TAG_LATEST="$ECR_REGISTRY/$ECR_REPOSITORY:latest" | |
| echo "image_uri_latest=$IMAGE_TAG_LATEST" >> $GITHUB_OUTPUT | |
| echo "ecr_repository=$ECR_REPOSITORY" >> $GITHUB_OUTPUT | |
| - name: Build and push Docker image | |
| id: build-image-and-push-to-ecr | |
| run: | | |
| docker buildx build --platform linux/arm64 -t ${{ vars.LAMBDA_FUNCTION_NAME }} --file Dockerfile.lambda . | |
| docker tag ${{ vars.LAMBDA_FUNCTION_NAME }}:latest ${{ steps.set-image-uris.outputs.image_uri_latest }} | |
| docker push ${{ steps.set-image-uris.outputs.image_uri_latest }} | |
| - name: Update Lambda function | |
| run: | | |
| aws lambda update-function-code \ | |
| --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} \ | |
| --image-uri ${{ steps.set-image-uris.outputs.image_uri_latest }} \ | |
| --region ${{ vars.AWS_REGION }} | |
| # Capture Lambda Function URL for GitHub Deployment | |
| - name: Get Lambda Function URL | |
| id: get-function-url | |
| run: | | |
| FUNCTION_URL=$(aws lambda get-function-url-config --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} --query 'FunctionUrl' --output text --region ${{ vars.AWS_REGION }} || echo '') | |
| echo "url=$FUNCTION_URL" >> $GITHUB_OUTPUT | |
| - name: Create GitHub Deployment Record | |
| uses: chrnorm/deployment-action@v2 | |
| id: create-github-deployment | |
| with: | |
| token: ${{ github.token }} | |
| environment: "production" | |
| environment-url: ${{ steps.get-function-url.outputs.url }} | |
| description: "Lambda Deployment" |