Merge pull request #18 from 7SOATSquad30/feature/lambda #18
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: Deploy Lambda | |
on: | |
push: | |
branches: | |
- main | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: us-east-1 | |
jobs: | |
build_and_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout do repositório | |
uses: actions/checkout@v4 | |
- name: Configurar credenciais AWS | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Instalar dependências necessárias | |
run: sudo apt-get update && sudo apt-get install -y xz-utils zip | |
- name: Construir pacote de implantação | |
run: | | |
set -e | |
make build | |
if [ ! -f deployment_package.zip ]; then | |
echo "Arquivo deployment_package.zip não encontrado!"; | |
exit 1; | |
fi | |
provision_infra: | |
runs-on: ubuntu-latest | |
needs: build_and_deploy | |
steps: | |
- name: Configurar credenciais AWS | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Instalar Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Cache do Terraform | |
uses: actions/cache@v3 | |
with: | |
path: ~/.terraform.d | |
key: terraform-${{ runner.os }}-${{ hashFiles('infra/**/*.tf') }} | |
restore-keys: terraform-${{ runner.os }}- | |
- name: Inicializar Terraform | |
working-directory: infra | |
run: terraform init | |
- name: Planejar Terraform | |
working-directory: infra | |
run: terraform plan -out=tfplan | |
- name: Aplicar Terraform | |
working-directory: infra | |
run: terraform apply -auto-approve tfplan | |
deploy_lambda: | |
runs-on: ubuntu-latest | |
needs: provision_infra | |
steps: | |
- name: Configurar credenciais AWS | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Implantar a AWS Lambda | |
run: | | |
aws lambda update-function-code \ | |
--function-name LambdaProcessadorVideos \ | |
--zip-file fileb://deployment_package.zip | |
- name: Limpeza pós-deploy | |
run: make clean | |
- name: Notificar sucesso do deploy | |
if: success() | |
run: echo "Deploy concluído com sucesso para LambdaProcessadorVideos em $AWS_REGION!" | |
- name: Notificar falha do deploy | |
if: failure() | |
run: echo "Falha no deploy da LambdaProcessadorVideos. Verifique os logs." |