Skip to content

Commit

Permalink
feature: completed part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
guillevalin committed Nov 10, 2024
1 parent 7fe7c80 commit 517bdcf
Show file tree
Hide file tree
Showing 17 changed files with 973 additions and 1,457 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/deploy-getandpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy Lambda - Obtener datos y publica en tópico SNS

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
env:
DOCKER_REPO: guillevalin/app-getandpublish
LAMBDA_IMAGE_TAG: "latest"
run: |
cd app-getandpublish
docker build -t $DOCKER_REPO:$LAMBDA_IMAGE_TAG .
docker push $DOCKER_REPO:$LAMBDA_IMAGE_TAG
- name: Set up AWS CLI
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: "us-east-1"

- name: Deploy to AWS Lambda
env:
LAMBDA_FUNCTION_NAME: "app-getandpublish"
LAMBDA_ROLE: ${{ secrets.LAMBDA_ROLE }}
DOCKER_REPO_URI: "guillevalin/app-getandpublish:latest"
run: |
aws lambda create-function \
--function-name $LAMBDA_FUNCTION_NAME \
--package-type Image \
--code ImageUri=$DOCKER_REPO_URI \
--role $LAMBDA_ROLE \
--region us-east-1 \
|| aws lambda update-function-code \
--function-name $LAMBDA_FUNCTION_NAME \
--image-uri $DOCKER_REPO_URI \
--region us-east-1
54 changes: 54 additions & 0 deletions .github/workflows/deploy-suscriptor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy Lambda - Suscriptor a tópico SNS

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
env:
DOCKER_REPO: guillevalin/app-suscriptor
LAMBDA_IMAGE_TAG: "latest"
run: |
cd app-suscriptor
docker build -t $DOCKER_REPO:$LAMBDA_IMAGE_TAG .
docker push $DOCKER_REPO:$LAMBDA_IMAGE_TAG
- name: Set up AWS CLI
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: "us-east-1"

- name: Deploy to AWS Lambda
env:
LAMBDA_FUNCTION_NAME: "app-suscriptor"
LAMBDA_ROLE: ${{ secrets.LAMBDA_ROLE }}
DOCKER_REPO_URI: "guillevalin/app-suscriptor:latest"
run: |
aws lambda create-function \
--function-name $LAMBDA_FUNCTION_NAME \
--package-type Image \
--code ImageUri=$DOCKER_REPO_URI \
--role $LAMBDA_ROLE \
--region us-east-1 \
|| aws lambda update-function-code \
--function-name $LAMBDA_FUNCTION_NAME \
--image-uri $DOCKER_REPO_URI \
--region us-east-1
39 changes: 0 additions & 39 deletions .github/workflows/deploy.yml

This file was deleted.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ Finalmente, esto se ve representado en el siguiente diagrama de arquitectura de
# Parte 2: Aplicaciones y flujo CI/CD

## API HTTP
- Se creó un handler simple de Lambda que expone dos endpoints. Un endpoint GET el que consultará la base de datos y devolverá las rows de una tabla en formato JSON
- Se creó un handler simple de Lambda que expone dos endpoints. Un endpoint GET el que consultará la base de datos y devolverá las rows de una tabla en formato JSON y un endpoint POST que publicará un mensaje en el tópico SNS.
-

## Deploy
- Se creó workflow de Github Actions que hace deploy de la función Lambda a una cuenta AWS cuyos parámetros se definen en secrets de Github.
- Ambos scripts son de ejecución manual.

## Ingesta a BBDD
- Se creó método POST que ingesta directamente a la base de datos.
- Se utilizará una suscripción a SNS a una función Lambda que insertará el mensaje en la base de datos.
- Se dejó un snippet simple de función lambda en la carpeta `app-suscriptor` que se utilizaría para insertar datos en la base de datos.
- Se dejó código terraform para desplegar la suscripción al tópico SNS que invocará esta función Lambda en `infraestructura/lambda-sub.tf`.

## Diagrama de arquitectura.
- El diagrama general fue explicado en la parte 1 de este README.
Expand Down
Loading

0 comments on commit 517bdcf

Please sign in to comment.