Fix more bugs
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
This commit is contained in:
parent
e8d72f88b2
commit
4ba82198de
|
@ -16,3 +16,15 @@ data "template_file" "userdata" {
|
|||
ENDPOINT = "${module.apigw.api_endpoint}"
|
||||
}
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "this" {
|
||||
statement {
|
||||
effect = "Allow"
|
||||
actions = ["dynamodb:PutItem"]
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["*"]
|
||||
}
|
||||
resources = ["arn:aws:dynamodb:us-east-1:478157316333:table/AWSDynamoDB-g3"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,34 +2,49 @@
|
|||
<meta charset="UTF-8">
|
||||
<html>
|
||||
<head>
|
||||
<title>ITBA - Cloud</title>
|
||||
<title>BSMSapp</title>
|
||||
<div align="center">
|
||||
<!-- Esta es mi función -->
|
||||
<script>
|
||||
function getImage() {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
document.getElementById("replace").innerHTML = this.responseText;
|
||||
}
|
||||
};
|
||||
|
||||
xhttp.open("GET", "${ENDPOINT}/resource", true);
|
||||
xhttp.send();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<!-- Este es mi código -->
|
||||
<br><br>
|
||||
<body bgcolor="#FFFFFF" text="Black">
|
||||
<h1><span id="replace">Bienvenidos, estimados Alumnos.</span></h1>
|
||||
<h1><span id="replace">BSMSapp</span></h1>
|
||||
|
||||
<button onclick="getImage()">Pinchame</button>
|
||||
<br><br>
|
||||
<img src="images/image1.png" , width=35%, height=35%>
|
||||
|
||||
<p>Este lab está desarrollado por la cátedra de Cloud Computing</p>
|
||||
<form id="myForm">
|
||||
<input value="0" name="id"/>
|
||||
<br>
|
||||
<input value="0" name="stock"/>
|
||||
<br><br>
|
||||
<input type="submit" value="Upload"/>
|
||||
</form>
|
||||
</body>
|
||||
</div>
|
||||
|
||||
</html>
|
||||
|
||||
<script>
|
||||
const thisForm = document.getElementById('myForm');
|
||||
thisForm.addEventListener('submit', async function (e) {
|
||||
e.preventDefault();
|
||||
// console.log(thisForm)
|
||||
// console.log(new FormData(thisForm).entries())
|
||||
const formData = new FormData(thisForm).entries()
|
||||
const str = JSON.stringify(Object.fromEntries(formData))
|
||||
console.log(str.replace(/\"/g, ''))
|
||||
let test = {
|
||||
id: 212311111,
|
||||
stock: 131211
|
||||
}
|
||||
const response = await fetch("${ENDPOINT}/resource", {
|
||||
method: 'POST',
|
||||
// mode: 'cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
// body: str.replace(/\"/g, '')
|
||||
body: JSON.stringify(test)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log(result)
|
||||
});
|
||||
</script>
|
|
@ -5,6 +5,12 @@ provider "aws" {
|
|||
shared_credentials_files = ["~/.aws/credentials"]
|
||||
profile = "default"
|
||||
|
||||
skip_requesting_account_id = true
|
||||
skip_get_ec2_platforms = true
|
||||
skip_metadata_api_check = true
|
||||
skip_region_validation = true
|
||||
skip_credentials_validation = true
|
||||
|
||||
default_tags {
|
||||
tags = {
|
||||
author = "g3"
|
||||
|
|
|
@ -1,3 +1,42 @@
|
|||
locals {
|
||||
private_inbound = [
|
||||
{
|
||||
rule_number = 100
|
||||
rule_action = "allow"
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_block = "10.0.1.0/24"
|
||||
},
|
||||
{
|
||||
rule_number = 110
|
||||
rule_action = "allow"
|
||||
from_port = 80
|
||||
to_port = 80
|
||||
protocol = "tcp"
|
||||
cidr_block = "10.0.2.0/24"
|
||||
},
|
||||
]
|
||||
private_outbound = [
|
||||
{
|
||||
rule_number = 100
|
||||
rule_action = "allow"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
protocol = "tcp"
|
||||
cidr_block = "10.0.1.0/24"
|
||||
},
|
||||
{
|
||||
rule_number = 110
|
||||
rule_action = "allow"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
protocol = "tcp"
|
||||
cidr_block = "10.0.2.0/24"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# VPC Module (from terraform-aws-modules)
|
||||
################################################################################
|
||||
|
@ -24,6 +63,10 @@ module "vpc" {
|
|||
manage_default_route_table = true
|
||||
default_route_table_tags = { Name = "vpc-g3-bsmsapp-default" }
|
||||
|
||||
private_dedicated_network_acl = true
|
||||
private_inbound_acl_rules = local.private_inbound
|
||||
private_outbound_acl_rules = local.private_outbound
|
||||
|
||||
manage_default_security_group = true
|
||||
default_security_group_tags = { Name = "vpc-g3-bsmsapp-default" }
|
||||
|
||||
|
@ -49,28 +92,9 @@ module "vpc_endpoints" {
|
|||
service = "dynamodb"
|
||||
service_type = "Gateway"
|
||||
route_table_ids = flatten([module.vpc.intra_route_table_ids, module.vpc.private_route_table_ids, module.vpc.public_route_table_ids])
|
||||
policy = data.aws_iam_policy_document.dynamodb_endpoint_policy.json # TODO: usar policy de abajo: (ahora lo estamos cargando a mano)
|
||||
# {
|
||||
# "Version": "2012-10-17",
|
||||
# "Statement": [
|
||||
# {
|
||||
# "Principal": "*",
|
||||
# "Effect": "Allow",
|
||||
# "Action": [
|
||||
# "dynamodb:BatchGetItem",
|
||||
# "dynamodb:GetItem",
|
||||
# "dynamodb:Scan",
|
||||
# "dynamodb:Query",
|
||||
# "dynamodb:BatchWriteItem",
|
||||
# "dynamodb:PutItem",
|
||||
# "dynamodb:UpdateItem",
|
||||
# "dynamodb:DeleteItem"
|
||||
# ],
|
||||
# "Resource": "arn:aws:dynamodb:us-east-1:025685231147:table/AWSDynamoDB-g3"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
policy = data.aws_iam_policy_document.this.json
|
||||
tags = { Name = "dynamodb-vpc-endpoint" }
|
||||
security_group_ids = [aws_security_group.dynamodb_sg.id]
|
||||
},
|
||||
lambda = {
|
||||
service = "lambda"
|
||||
|
@ -90,11 +114,60 @@ module "vpc_endpoints" {
|
|||
# Supporting Resources
|
||||
################################################################################
|
||||
|
||||
resource "aws_vpc_endpoint" "dynamodb_endpoint" {
|
||||
vpc_id = module.vpc.vpc_id
|
||||
service_name = "com.amazonaws.us-east-1.dynamodb"
|
||||
}
|
||||
|
||||
data "aws_security_group" "default" {
|
||||
name = "default"
|
||||
vpc_id = module.vpc.vpc_id
|
||||
}
|
||||
|
||||
resource "aws_security_group" "dynamodb_sg" {
|
||||
name_prefix = "vpc-g3-bsmsapp-dsg"
|
||||
description = "Allow HTTPs outbound traffic"
|
||||
vpc_id = module.vpc.vpc_id
|
||||
|
||||
egress {
|
||||
description = "HTTPs to DynamoDB"
|
||||
from_port = 443
|
||||
to_port = 443
|
||||
protocol = "tcp"
|
||||
prefix_list_ids = [aws_vpc_endpoint.dynamodb_endpoint.prefix_list_id]
|
||||
}
|
||||
|
||||
tags = {
|
||||
Name = "vpc-g3-bsmsapp"
|
||||
}
|
||||
}
|
||||
|
||||
# resource "aws_network_acl" "private_nacl" {
|
||||
# vpc_id = module.vpc.vpc_id
|
||||
|
||||
# egress {
|
||||
# protocol = "tcp"
|
||||
# rule_no = 200
|
||||
# action = "allow"
|
||||
# cidr_block = ["10.0.1.0/24", "10.0.2.0/24"]
|
||||
# from_port = 443
|
||||
# to_port = 443
|
||||
# }
|
||||
|
||||
# ingress {
|
||||
# protocol = "tcp"
|
||||
# rule_no = 100
|
||||
# action = "allow"
|
||||
# cidr_block = ["10.0.1.0/24", "10.0.2.0/24"]
|
||||
# from_port = 80
|
||||
# to_port = 80
|
||||
# }
|
||||
|
||||
# tags = {
|
||||
# Name = "vpc-g3-bsmsapp"
|
||||
# }
|
||||
# }
|
||||
|
||||
data "aws_iam_policy_document" "dynamodb_endpoint_policy" {
|
||||
statement {
|
||||
effect = "Deny"
|
||||
|
@ -152,3 +225,4 @@ resource "aws_security_group" "vpc_tls" {
|
|||
Name = "vpc-g3-bsmsapp"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -1,35 +1,26 @@
|
|||
import json
|
||||
import boto3
|
||||
|
||||
|
||||
def main (event, context):
|
||||
payload = event
|
||||
payload = payload["Records"][0]
|
||||
body = payload["body"]
|
||||
body = body.replace('\n', '')
|
||||
print(body)
|
||||
#body = json.dumps(body)
|
||||
body = json.loads(body)
|
||||
query = body["body-json"]
|
||||
print("payload-> " + str(query) )
|
||||
|
||||
client = boto3.resource('dynamodb', region_name="us-east-1")
|
||||
table = client.Table("AWSDynamoDB-g3")
|
||||
|
||||
table.put_item(Item={
|
||||
"id": {
|
||||
"N": "1"
|
||||
},
|
||||
"stock": {
|
||||
"N": "2212"
|
||||
},
|
||||
})
|
||||
table.put_item(Item=query)
|
||||
|
||||
resp = {
|
||||
"statusCode": 200,
|
||||
"headers": {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
"body": "El lab ha sido finalizado correctamente"
|
||||
"body": "El elemento fue agregado."
|
||||
}
|
||||
|
||||
return resp
|
Loading…
Reference in New Issue