![cloud file workflow](https://private-user-images.githubusercontent.com/107063397/287425422-24d39502-8fbc-4e58-b2b4-5bb51a40998c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3Nzk0ODIsIm5iZiI6MTcyNTc3OTE4MiwicGF0aCI6Ii8xMDcwNjMzOTcvMjg3NDI1NDIyLTI0ZDM5NTAyLThmYmMtNGU1OC1iMmI0LTViYjUxYTQwOTk4Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwOFQwNzA2MjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kZDY1MDhjYWI4NDgzZjgwZWM3MTc1NjBlMDRkNTRlYmMzY2M5MjkzNDI0ZDgxYTdkMDFiMWNiNDdjNWRlZWE1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.5nxZa5m3Icnn4DZWLtWoZeS3iGbgendaGAsJmYkIOH8)
In this application, a user can create an account and upload a profile picture. This will save their information on RDS in a MySQL database, it will then send an email to my personal email telling me a user has created an account. A user can enter their credentials and allow them to login to the main webapp. A user can then select up to 5 emails to upload a file to. Each address will recieve an email with a link that allows them to download the uploaded file from S3.
Flask
Used to operate the webserverBoto3
Python SDK used to connecto to S3 buckets and Lambda functions (can do other aws services)S3
Store profile pictures and uploaded filesAWS Lambda
Calls SNS and SES functionsSNS
Sends email to webpage owner when new account is createdSES
Sends file download link to specified emailsMySQL/RDS
Store user credentials, profile pictures, and file uploadsEC2
Host Flask WebServer/applicationIAM
Set access and identity permissions that we use when connecting with Boto3
When people access the application, they can only add files if they've added credentials to the MySQL database in AWS RDS. Anyone can connect, as by default, the "/add" route has permissions built into it to add a username and password to S3, my email is alerted after the function is invoked.
import boto3
def lambda_handler(event, context):
ACCESS_KEY = "AKIA3SR6ZX6FT4OAXVPJ"
SECRET_KEY = "*******************"
AWS_REGION = "us-east-1"
email = event.get("email")
sns_client = boto3.client(
"sns",
region_name=AWS_REGION,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
# do i need aws_access_key_id = ACCESS KEY or SECRET_KEY
sns_client.publish(
TopicArn="arn:aws:sns:us-east-1:795774402443:mksns",
Message="New user Added: " + email,
Subject="New User",
)
After that, they can use the "/login" route, which allows the user to input data and call the "/uploadSend" endpoint. This stores data in s3, keeps track of the file name in the MySQL database, and invokes my lambda function "lambdaSendFileLink" which sends an email to the entered emails that contains a link.
import boto3
import json
ACCESS_KEY = "AKIA3SR6ZX6FT4OAXVPJ"
SECRET_KEY = "********************"
AWS_REGION = "us-east-1"
def lambda_handler(event, context):
ACCESS_KEY = "AKIA3SR6ZX6FT4OAXVPJ"
SECRET_KEY = "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"
AWS_REGION = "us-east-1"
emails = event.get("email")
botoS3 = boto3.client(
"s3",
region_name=AWS_REGION,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
botoSES = boto3.client("ses", region_name="us-east-1")
key = event.get("filename")
bucket = "mkcloudbucket"
url = f"https://{bucket}.s3.amazonaws.com/{key}"
response = botoSES.send_email(
Destination={"ToAddresses": emails},
Message={
"Body": {
"Text": {
"Charset": "UTF-8",
"Data": "Your file is ready to download: " + url,
}
},
"Subject": {
"Charset": "UTF-8",
"Data": "Test email",
},
},
Source="[email protected]",
)
print(response)
return {
"statusCode": 200,
"body": json.dumps(
"Email Sent Successfully. MessageId is: " + response["MessageId"]
),
}
- Main page login
- Create account page
- File upload app page
![display](https://private-user-images.githubusercontent.com/107063397/258663813-55885c0d-49e2-484a-a4b9-a19b043f3d1d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3Nzk0ODIsIm5iZiI6MTcyNTc3OTE4MiwicGF0aCI6Ii8xMDcwNjMzOTcvMjU4NjYzODEzLTU1ODg1YzBkLTQ5ZTItNDg0YS1hNGI5LWExOWIwNDNmM2QxZC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwOFQwNzA2MjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0wYjA5OWM0Yzg2ZTQzODg1YzBkMWQ4ZDQ4MTBmYWNkZGZmNDhmZjRhMmE1MTY1ZDE2YjBiOGQwNDIyZjI5YjcyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.lNHLQSETI2SH2AIM7a1fkYJV003p2FPRxSRfFba2JL8)
This is the notification for new users:
This is what is recieved when someone shares a file:
![email](https://private-user-images.githubusercontent.com/107063397/258663791-b6fa9a79-4367-48f8-a0e2-98c87c25e8e8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3Nzk0ODIsIm5iZiI6MTcyNTc3OTE4MiwicGF0aCI6Ii8xMDcwNjMzOTcvMjU4NjYzNzkxLWI2ZmE5YTc5LTQzNjctNDhmOC1hMGUyLTk4Yzg3YzI1ZThlOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwOFQwNzA2MjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lZTAyNjM5NzdlNTZlYmY0ZjI2YzllMWQ3ZGM1YWM5ZjViOTU2ZGU3Nzg5YjkwNjA5MmNhOGQ4ZTdhOTkyYzFmJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.YlnU6HjMsQRwugL_BZU6Xi0BCzFfY8nXUdm4efJmiuw)