A solution to store an HTTP request body as a file into Amazon Simple Storage Service (S3), via Amazon API Gateway as an entrypoint.
For instance, this solution can be used as a webhook for third parties to push JSON data for further processing.
This solution will upload files into S3 in <PREFIX>_<EPOCH>_<GUID><SUFFIX>
format.
Please note
- This is a sample solution. Extend as required for your organisational requirements / governance / compliance purposes.
- In this example, an API key is used for authentication. More info here.
- This solution is meant to be used with trusted third parties. The solution does not check the files for vulnerabilities.
Defaults
Name | Default |
---|---|
PREFIX |
PREFIX |
SUFFIX |
.json |
Ex:
PREFIX_1622613486775_eeea3f06-93ac-46e7-9b15-3c319c6fda8a.json
- Run command
sam build
- Run command
sam deploy --guided
- When asked, provide the information required.
- Copy the
outputs
section. These will be required later.
First, let's get the API key value. Replace the API Key
below, from the corresponding value in the outputs
section, and run the following command:
aws apigateway get-api-key --api-key <API Key> --include-value
. In the resulting response, copy the value
. This value will be used below.
After replacing the API Url
from the corresponding value in the outputs
section, and the API Key Value
below with value copied from above, run the following CURL
command.
curl -iX POST '<API Url>' \
--header 'x-api-key: <API Key Value>' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": "test"
}'
In the AWS Management Console, go to the S3 bucket (the name of the bucket will be in the outputs
section). You will see a file in the S3 bucket with the following payload:
{
"message": "test"
}
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.