Skip to content

Instantly share code, notes, and snippets.

@alvonx
Last active March 21, 2023 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvonx/3983066b189cdb5fda0df71325afc8f3 to your computer and use it in GitHub Desktop.
Save alvonx/3983066b189cdb5fda0df71325afc8f3 to your computer and use it in GitHub Desktop.
import json
import boto3
import random
from botocore.vendored import requests
def random_url(plen=10, ucfirst=True, spchar=True):
if plen >= 6 and plen % 2 != 0:
plen = plen+1
elif plen < 8:
return None, 'length too small'
length = plen
conso = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
vocal = ['a', 'e', 'i', 'o', 'u']
spchars = ['!', '@', '#', '$', '%', '^', '*', '&', '*', '-', '+', '?']
password = ''
pmax = length // 2
for i in range(1, pmax + 1):
password += conso[random.randint(0, 19)]
password += vocal[random.randint(0, 4)]
return password
def get_user_profile():
random_user = random.randint(0, 99)
return random_user
def lambda_handler(event, context):
user_ip = event['requestContext']['identity']['sourceIp']
requestTimeEpoch = event['requestContext']['requestTimeEpoch']
user_url = random_url()
user_img = get_user_profile()
ssm_client = boto3.client('ssm')
response = ssm_client.send_command(
DocumentName='AWS-RunShellScript',
Parameters={
'commands': [
f"cp /var/www/html/default.html /var/www/html/{user_url}.html",
f"sed -i 's/public_ip/{user_ip}/' /var/www/html/{user_url}.html",
f"sed -i 's/public_img/{user_img}/' /var/www/html/{user_url}.html",
f"sed -i 's/startTimeEpoch/{requestTimeEpoch}/' /var/www/html/{user_url}.html"
]
},
InstanceIds=['i-<instance-id>']
)
return {
'statusCode': 200,
'body': json.dumps({
"msg": 'Hello from Lambda!',
"your-custom-html-url": f"http://ttpltech.in/{user_url}.html",
"extras": "page will gets deleted in 5 minutes"
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment