Skip to content

Commit

Permalink
- added new aws lambda functions for new subscriptions and usage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lley154 committed Oct 21, 2023
1 parent db4143a commit f6759b1
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
42 changes: 42 additions & 0 deletions aws/lambda-functions/subscriptions/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json
import os, re, base64
import boto3

def lambda_handler(event, context):

mypage = page_router(event['httpMethod'],event['queryStringParameters'],event['body'])

return mypage


def page_router(httpmethod,querystring,formbody):

if httpmethod == 'GET':
htmlFile = open('subscription.html', 'r')
htmlContent = htmlFile.read()
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent
}

if httpmethod == 'POST':

insert_record(formbody)

htmlFile = open('thankyou.html', 'r')
htmlContent = htmlFile.read()
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent
}

def insert_record(formbody):

formbody = formbody.replace("=", "' : '")
formbody = formbody.replace("&", "', '")
formbody = "INSERT INTO subscriptions value {'" + formbody + "'}"

client = boto3.client('dynamodb')
client.execute_statement(Statement= formbody)
24 changes: 24 additions & 0 deletions aws/lambda-functions/subscriptions/subscription.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<body>

<h2>Subscription Form</h2>

<form action="/dev" method="post">
<label for="providerId">ProviderId:</label><br>
<input type="text" id="providerId" name="providerId" ><br>
<label for="accountId">AccountId:</label><br>
<input type="text" id="accountId" name="accountId" ><br>
<label for="Tier Name">Tier Name:</label><br>
<input type="text" id="tier" name="tier" ><br><br>
<label for="Threshold">Threshold:</label><br>
<input type="text" id="threshold" name="threshold" ><br><br>
<label for="Threshold">Billing Cycle:</label><br>
<input type="text" id="cycle" name="cycle" ><br><br>
<label for="Threshold">Billing Start Date:</label><br>
<input type="date" id="billStart" name="billStart" ><br><br>
<input type="submit" value="Submit">
</form>

</body>
</html>
Binary file not shown.
8 changes: 8 additions & 0 deletions aws/lambda-functions/subscriptions/thankyou.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>

<h2>Thank you for your subscription!</h2>

</body>
</html>
8 changes: 8 additions & 0 deletions aws/lambda-functions/usage/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>

<h2>Error: usage threshold exceeded</h2>

</body>
</html>
42 changes: 42 additions & 0 deletions aws/lambda-functions/usage/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json
import os, re, base64
import boto3

def lambda_handler(event, context):

mypage = page_router(event['httpMethod'],event['queryStringParameters'],event['body'])

return mypage


def page_router(httpmethod,querystring,formbody):

if httpmethod == 'GET':
htmlFile = open('usage.html', 'r')
htmlContent = htmlFile.read()
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent
}

if httpmethod == 'POST':

insert_record(formbody)

htmlFile = open('status.html', 'r')
htmlContent = htmlFile.read()
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent
}

def insert_record(formbody):

formbody = formbody.replace("=", "' : '")
formbody = formbody.replace("&", "', '")
formbody = "INSERT INTO usage value {'" + formbody + "'}"

client = boto3.client('dynamodb')
client.execute_statement(Statement= formbody)
8 changes: 8 additions & 0 deletions aws/lambda-functions/usage/status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>

<h2>Success: Usage permitted</h2>

</body>
</html>
18 changes: 18 additions & 0 deletions aws/lambda-functions/usage/usage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<body>

<h2>Usage Form</h2>

<form action="/dev" method="post">
<label for="providerId">ProviderId:</label><br>
<input type="text" id="providerId" name="providerId" ><br>
<label for="accountId">AccountId:</label><br>
<input type="text" id="accountId" name="accountId" ><br>
<label for="Tier Name">Usage:</label><br>
<input type="text" id="usage" name="usage" ><br><br>
<input type="submit" value="Submit">
</form>

</body>
</html>
Binary file added aws/lambda-functions/usage/usage.zip
Binary file not shown.

0 comments on commit f6759b1

Please sign in to comment.