Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Proyecto Platzi

## Despliegue del proyeto

### Pre-Requisitos
Expand Down
6 changes: 6 additions & 0 deletions dynamo/dynamo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
aws cloudformation deploy \
--region us-east-1 \
--parameter-overrides DynamoName="lablambda" DynamoKey="dni" \
--stack-name dynamo-lambda-lab \
--template-file ./dynamo.yml
30 changes: 30 additions & 0 deletions dynamo/dynamo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
DynamoName:
Type: String
DynamoKey:
Type: String

Resources:
DynamoLab:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref DynamoName
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: !Ref DynamoKey
AttributeType: S
KeySchema:
- AttributeName: !Ref DynamoKey
KeyType: HASH
SSESpecification:
SSEEnabled: true
Outputs:
DynamoName:
Value: !Ref DynamoLab
Export:
Name: DynamoLab
DynamoNameArn:
Value: !GetAtt DynamoLab.Arn
Export:
Name: DynamoLabArn
11 changes: 6 additions & 5 deletions lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
import os
from boto3.dynamodb.conditions import Key

DYNAMO_PLATZI = os.environ['DYNAMO_PLATZI']
# Hola a todos companeros estoy editando el codigo porque soy developer

DYNAMO_BD = os.environ['DYNAMO_BD']

class DynamoAccessor:
def __init__(self, dynamo_table):
dynamo_db = boto3.resource('dynamodb')
self.table = dynamo_db.Table(dynamo_table)

def get_data_from_dynamo(self, cc):
response = self.table.query(KeyConditionExpression=Key('cc').eq(cc))
def get_data_from_dynamo(self, dni):
response = self.table.query(KeyConditionExpression=Key('dni').eq(dni))
return response["Items"][0] if any(response["Items"]) else None

def lambda_handler(event, context):
dynamo_backend = DynamoAccessor(DYNAMO_PLATZI)
db_element = dynamo_backend.get_data_from_dynamo(event['cc'])
dynamo_backend = DynamoAccessor(DYNAMO_BD)
db_element = dynamo_backend.get_data_from_dynamo(event['dni'])
return db_element

7 changes: 7 additions & 0 deletions prereq/aws-codepipeline-prereq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
aws cloudformation deploy \
--region us-east-1 \
--stack-name codepipeline-lambda-prereq \
--template-file ./aws-codepipeline-prereq.yml \
--capabilities CAPABILITY_IAM \
--capabilities CAPABILITY_NAMED_IAM
Loading