Build and push container to ECR and Lambda #8
Workflow file for this run
This file contains 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 push container to ECR and Lambda | |
on: | |
release: | |
types: [ released ] | |
jobs: | |
deploy: | |
name: Build Docker and Deploy Lambda | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- 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: ${{ secrets.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push the image to ECR | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.REPO_NAME }} | |
IMAGE_TAG: latest | |
run: | | |
cd ./aws-lambda | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
echo "Pushing image to ECR..." | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" | |
- name: Deploy image to Lambda | |
id: deploy-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.REPO_NAME }} | |
IMAGE_TAG: latest | |
run: | | |
aws lambda update-function-code \ | |
--function-name dlx-dl-lambda \ | |
--image-uri $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
- name: Update EventBridge Rules | |
id: update-rules | |
run: | | |
aws events put-rule \ | |
--name dlx-dl-lambda-bib \ | |
--schedule-expression "rate(10 minutes)" | |
aws events put-targets \ | |
--rule dlx-dl-lambda-bib \ | |
--targets '[{"Id":"1","Arn":"${{ secrets.FUNCTION_ARN }}","Input":"{\"source\":\"dlx-dl-lambda\",\"type\":\"bib\",\"modified_within\":86400,\"queue\":true}"}]' | |
aws events put-rule \ | |
--name dlx-dl-lambda-auth \ | |
--schedule-expression "rate(10 minutes)" | |
aws events put-targets \ | |
--rule dlx-dl-lambda-auth \ | |
--targets '[{"Id":"1","Arn":"${{ secrets.FUNCTION_ARN }}","Input":"{\"source\":\"dlx-dl-lambda\",\"type\":\"auth\",\"modified_within\":86400,\"queue\":true}"}]' |