Last active
March 21, 2023 07:56
-
-
Save alvonx/f80e14075a1fd53ad4ac029b5df1c99c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
def lambda_handler(event, context): | |
page_name = event['queryStringParameters']['page'] | |
cover_name = event['queryStringParameters']['cover'] | |
print(page_name) | |
ssm_client = boto3.client('ssm') | |
response = ssm_client.send_command( | |
DocumentName='AWS-RunShellScript', | |
Parameters={ | |
'commands': [ | |
f"sed -i 's/Cover-Name/{cover_name}/' /var/www/html/{page_name}.html" | |
] | |
}, | |
InstanceIds=['i-<instance-id>'] | |
) | |
return { | |
'statusCode': 200, | |
'headers': { | |
'Access-Control-Allow-Headers': 'Content-Type', | |
'Access-Control-Allow-Origin': '*', | |
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET' | |
}, | |
'body': json.dumps({ | |
"msg": "hello", | |
"page": page_name, | |
"cover": cover_name | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment