Add initial example
This commit is contained in:
parent
039ee88b0e
commit
a2444279e9
|
@ -0,0 +1,60 @@
|
|||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
*.manifest
|
||||
*.spec
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
*.mo
|
||||
*.pot
|
||||
target/
|
||||
.ipynb_checkpoints
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
.python-version
|
||||
__pypackages__/
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
/site
|
||||
.pyre/
|
||||
.terraform/
|
||||
.terraform.*
|
||||
terraform.tfstate*
|
||||
.terraform*
|
|
@ -1,5 +1,13 @@
|
|||
# BSMSapp
|
||||
|
||||
Best Stock Management System application.
|
||||
|
||||
## Diagrama de arquitectura
|
||||
|
||||
<!--  -->
|
||||
|
||||
<img src="docs/diagram.png" alt="drawing" width="1000"/>
|
||||
|
||||
## Autores
|
||||
- Bellver, Ezequiel (61268)
|
||||
- Burgos, Santiago Eduardo (55193)
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 207 KiB |
|
@ -0,0 +1,17 @@
|
|||
# ---------------------------------------------------------------------------
|
||||
# Amazon S3 datasources
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
data "aws_iam_policy_document" "this" {
|
||||
|
||||
statement {
|
||||
sid = "PublicReadGetObject"
|
||||
effect = "Allow"
|
||||
actions = ["s3:GetObject"]
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["*"]
|
||||
}
|
||||
resources = ["${aws_s3_bucket.this.arn}/*"]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
# Amazon S3
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# 1 - S3 bucket
|
||||
resource "aws_s3_bucket" "this" {
|
||||
bucket = var.bucket_name
|
||||
object_lock_enabled = false
|
||||
}
|
||||
|
||||
# 2 -Bucket policy
|
||||
resource "aws_s3_bucket_policy" "this" {
|
||||
count = var.objects != {} ? 1 : 0
|
||||
|
||||
bucket = aws_s3_bucket.this.id
|
||||
policy = data.aws_iam_policy_document.this.json
|
||||
}
|
||||
|
||||
# 3 -Website configuration
|
||||
resource "aws_s3_bucket_website_configuration" "this" {
|
||||
bucket = aws_s3_bucket.this.id
|
||||
|
||||
index_document {
|
||||
suffix = "index.html"
|
||||
}
|
||||
|
||||
error_document {
|
||||
key = "error.html"
|
||||
}
|
||||
}
|
||||
|
||||
# 4 - Access Control List
|
||||
resource "aws_s3_bucket_acl" "this" {
|
||||
bucket = aws_s3_bucket.this.id
|
||||
acl = var.bucket_acl
|
||||
}
|
||||
|
||||
# 5 - Upload objects
|
||||
resource "aws_s3_object" "this" {
|
||||
for_each = try(var.objects, {}) #{ for object, key in var.objects: object => key if try(var.objects, {}) != {} }
|
||||
|
||||
bucket = aws_s3_bucket.this.id
|
||||
key = try(each.value.rendered, replace(each.value.filename, "html/", "")) # remote path
|
||||
source = try(each.value.rendered, format("../../resources/%s", each.value.filename)) # where is the file located
|
||||
content_type = each.value.content_type
|
||||
storage_class = try(each.value.tier, "STANDARD")
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
# --------------------------------------------------------------------
|
||||
# Amazon S3 buckets output
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
output "id" {
|
||||
description = "The bucket domain name. Will be of format bucketname.s3.amazonaws.com"
|
||||
value = aws_s3_bucket.this.id
|
||||
}
|
||||
|
||||
output "arn" {
|
||||
description = "The ARN of the bucket. Will be of format arn:aws:s3:::bucketname"
|
||||
value = aws_s3_bucket.this.arn
|
||||
}
|
||||
|
||||
output "website_endpoint" {
|
||||
description = "The website endpoint, if the bucket is configured with a website. If not, this will be an empty string"
|
||||
value = aws_s3_bucket.this.website_endpoint
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
# ------------------------------------------------------------------------
|
||||
# Amazon S3 variables
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
variable "bucket_name" {
|
||||
type = string
|
||||
description = "The name of the bucket. Must be less than or equal to 63 characters in length."
|
||||
}
|
||||
|
||||
variable "objects" {
|
||||
type = map(any)
|
||||
description = ""
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "block_public_access" {
|
||||
type = bool
|
||||
default = true
|
||||
description = "Determines the S3 account-level Public Access Block configuration. For more information about these settings, see the AWS S3 documentation: https://docs.aws.amazon.com/AmazonS3/latest/dev/access-control-block-public-access.html"
|
||||
}
|
||||
|
||||
variable "bucket_acl" {
|
||||
type = string
|
||||
default = "private"
|
||||
description = "The canned ACL to apply. Valid values are private, public-read, public-read-write, aws-exec-read, authenticated-read, and log-delivery-write. Defaults to private. For more information about these settings, see the AWS S3 documentation: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl"
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
terraform {
|
||||
required_version = ">= 1.0.6"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 4.10.0"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
# ---------------------------------------------------------------------------
|
||||
# Amazon API Gateway
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
resource "aws_api_gateway_rest_api" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
name = "AWSAPIGateway-${local.bucket_name}"
|
||||
description = "This lab was created by the Cloud Computing team"
|
||||
}
|
||||
|
||||
resource "aws_api_gateway_resource" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
path_part = "resource"
|
||||
parent_id = aws_api_gateway_rest_api.this.root_resource_id
|
||||
rest_api_id = aws_api_gateway_rest_api.this.id
|
||||
}
|
||||
|
||||
resource "aws_api_gateway_method" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
rest_api_id = aws_api_gateway_rest_api.this.id
|
||||
resource_id = aws_api_gateway_resource.this.id
|
||||
http_method = "GET"
|
||||
authorization = "NONE"
|
||||
}
|
||||
|
||||
resource "aws_api_gateway_integration" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
rest_api_id = aws_api_gateway_rest_api.this.id
|
||||
resource_id = aws_api_gateway_resource.this.id
|
||||
http_method = aws_api_gateway_method.this.http_method
|
||||
integration_http_method = "POST"
|
||||
type = "AWS_PROXY"
|
||||
uri = aws_lambda_function.this.invoke_arn
|
||||
}
|
||||
|
||||
resource "aws_api_gateway_deployment" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
rest_api_id = aws_api_gateway_rest_api.this.id
|
||||
|
||||
triggers = {
|
||||
redeployment = sha1(jsonencode([
|
||||
# aws_api_gateway_rest_api.this.body,
|
||||
aws_api_gateway_resource.this.id,
|
||||
aws_api_gateway_method.this.id,
|
||||
aws_api_gateway_integration.this.id,
|
||||
]))
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_api_gateway_stage" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
deployment_id = aws_api_gateway_deployment.this.id
|
||||
rest_api_id = aws_api_gateway_rest_api.this.id
|
||||
stage_name = "production"
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
# ---------------------------------------------------------------------------
|
||||
# Main resources
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
data "aws_region" "current" {
|
||||
provider = aws.aws
|
||||
}
|
||||
|
||||
data "aws_caller_identity" "current" {
|
||||
provider = aws.aws
|
||||
}
|
||||
|
||||
data "template_file" "userdata" {
|
||||
template = file("${path.module}/html/index.html")
|
||||
vars = {
|
||||
ENDPOINT = "${aws_api_gateway_stage.this.invoke_url}"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<html>
|
||||
<head>
|
||||
<title>ITBA - Cloud</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>
|
||||
|
||||
<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>
|
||||
</body>
|
||||
</div>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
# ---------------------------------------------------------------------------
|
||||
# AWS Lambda resources
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Lambda
|
||||
resource "aws_lambda_permission" "apigw_lambda" {
|
||||
provider = aws.aws
|
||||
|
||||
statement_id = "AllowExecutionFromAPIGateway"
|
||||
action = "lambda:InvokeFunction"
|
||||
function_name = aws_lambda_function.this.function_name
|
||||
principal = "apigateway.amazonaws.com"
|
||||
|
||||
source_arn = "arn:aws:execute-api:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:${aws_api_gateway_rest_api.this.id}/*/${aws_api_gateway_method.this.http_method}${aws_api_gateway_resource.this.path}"
|
||||
}
|
||||
|
||||
resource "aws_lambda_function" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
filename = "${local.path}/lambda/lambda.zip"
|
||||
function_name = "AWSLambdaHandler-${replace(local.bucket_name, "-", "")}"
|
||||
role = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/LabRole"
|
||||
handler = "lambda_handler.main"
|
||||
runtime = "python3.9"
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
locals {
|
||||
bucket_name = "b123123123123-itba-cloud-computing-personal"
|
||||
path = "../../resources"
|
||||
|
||||
s3 = {
|
||||
|
||||
# 1 - Website
|
||||
website = {
|
||||
bucket_name = local.bucket_name
|
||||
path = "../../resources"
|
||||
|
||||
objects = {
|
||||
error = {
|
||||
filename = "html/error.html"
|
||||
content_type = "text/html"
|
||||
}
|
||||
image1 = {
|
||||
filename = "images/image1.png"
|
||||
content_type = "image/png"
|
||||
}
|
||||
image2 = {
|
||||
filename = "images/image2.jpg"
|
||||
content_type = "image/jpeg"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 2 - WWW Website
|
||||
www-website = {
|
||||
bucket_name = "www.${local.bucket_name}"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
output "api_endpoint" {
|
||||
value = aws_api_gateway_stage.this.invoke_url
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
provider "aws" {
|
||||
alias = "aws"
|
||||
region = "us-east-1"
|
||||
|
||||
shared_credentials_files = ["~/.aws/credentials"]
|
||||
profile = "default"
|
||||
|
||||
default_tags {
|
||||
tags = {
|
||||
author = "g3"
|
||||
version = 1
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
# ---------------------------------------------------------------------------
|
||||
# Amazon S3 resources
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
module "s3" {
|
||||
for_each = local.s3
|
||||
source = "../../modules/s3"
|
||||
|
||||
providers = {
|
||||
aws = aws.aws
|
||||
}
|
||||
|
||||
bucket_name = each.value.bucket_name
|
||||
objects = try(each.value.objects, {})
|
||||
}
|
||||
|
||||
resource "aws_s3_object" "this" {
|
||||
provider = aws.aws
|
||||
|
||||
bucket = module.s3["website"].id
|
||||
key = "index.html"
|
||||
content = data.template_file.userdata.rendered
|
||||
content_type = "text/html"
|
||||
storage_class = "STANDARD"
|
||||
}
|
||||
|
||||
# Another way to use it, is to directly pass the following arguments to the resource
|
||||
|
||||
# templatefile("../../resources/html/index.html",
|
||||
# {
|
||||
# ENDPOINT = aws_api_gateway_rest_api.this.arn
|
||||
# })
|
|
@ -0,0 +1,10 @@
|
|||
terraform {
|
||||
required_version = ">= 1.0.6"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = ">= 4.10.0"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<html>
|
||||
<div align="center">
|
||||
|
||||
<head>
|
||||
<title>ITBA - Cloud</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="Black">
|
||||
<h1>Ups... algo ha salido mal...</h1>
|
||||
|
||||
<img src="images/image2.jpg">
|
||||
|
||||
<p>Por favor intenta de nuevo en algunos minutos</p>
|
||||
</body>
|
||||
</div>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8">
|
||||
<html>
|
||||
<head>
|
||||
<title>ITBA - Cloud</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}, 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>
|
||||
|
||||
<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>
|
||||
</body>
|
||||
</div>
|
||||
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
def main (event, context):
|
||||
print ("In lambda handler")
|
||||
|
||||
resp = {
|
||||
"statusCode": 200,
|
||||
"headers": {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
"body": "El lab ha sido finalizado correctamente"
|
||||
}
|
||||
|
||||
return resp
|
Loading…
Reference in New Issue