So now that my site is using Hugo for static HTML file generation, S3 to store the files, lambda to trigger the Hugo update, and CloudFront to serve images, the next step is to upload files to S3 directly from the browser. Thanks to my buddy Robert, he got me started and helped me get the API Gateway setup.
-
HTML page with input type of file with evaporate. Include the aws_key, bucket: and aws_url.
-
Update the signer.py function with the user arn and secret.
-
Add the signer to a new lambda function.
-
Add the timer to a new lambda function.
-
Add a new API Gateway or add to existing
-
Create a new Resource for the signer.
-
Create a new Method GET for the signer for the signer lambda function.
-
In the GET Method Request, add a URL Query String Parameters for “to_sign”.
-
In The GET Integration Request > Body Mapping Template for application/json, add the code
|
|
- In the GET Integration Response, Change the Header Mapping(?), change the Body Mapping Templates to only “text/html” and for the “text/html” add the code
|
|
-
In the GET Method Response, change the “Response Models for 200” to only “text/html”.
-
Enable CORS for the Method GET signer. Change Access-Control-Allow-Origin for the domain you’re using or ‘*’.
-
Create a new Resource for the timer.
-
Create a new Method GET for the timer for the timer lambda function above
-
Enable CORS for the Method GET timer. Change Access-Control-Allow-Origin for the domain you’re using or ‘*’.
-
Deploy the API and add the API endpoints to the HTML page.
-
In the S3 bucket that the file will be uploaded to, add the bucket policy:
|
|
- In the S3 bucket that the file will be uploaded to, add the CORS Configuration:
|
|
-
Upload an image and it should load into the S3 bucket.
-
Next I will use this to upload images and content files to the buckets, which will trigger an update to the site without having to login to the AWS console.