These go lambdas are responsible for returning pre-signed PUT and GET URLs from AWS S3, storing their metadata in a DynamoDB, and listing all this stored metadata.
The project is being built to deliver audio for a mobile app. This mobile application is called "Medo e delirio em brasilia", and it was created by persons that hear a podcast with the same name, very famous for "audio insertions" inside of podcast. The app creators would like all people who hear the podcast to have a chance to share these "audio insertions" with their friends and have some fun.
Before you start, be sure that you have AWS CLI, AWS SAM, Docker, and Go installed.
As an initial step, you should log into your AWS account and create a bucket, which will store your code.
Inside the Makefile, fill the local variable MY_AWS_PROFILE
with your local AWS profile name, and the variable CODE_BUCKET
with the bucket that you created to store your code. You can define a new project name, if you want, at the variable PROJECT_NAME
.
After this, go to the file template.yaml
and fill in the parameters BucketName
and DynamoTableName
to create a new bucket and dynamodb table. These two resources will be used in this API to store the files and the metadata.
You should run this command to deploy the API and also to create the dynamodb table and S3 bucket:
make deploy
To run and test the AWS Lambdas locally, you can run:
make dev
If you want to run the unit testing, run:
make unit-test-internal
You can also check the coverage report with this command:
make coverage-report
POST /audio
This route generates a pre-signed S3 URL to store the object.
A body object is required, example:
{
"fileName": "test",
}
Request:
curl -X POST -H "Content-Type: application/json" -d '{
"fileName": "test",
}' http://localhost:3000/audio
Expected responses:
Status Code: 201
Body:
{
"url": "http://aws.url"
}
Status Code: 400
Reason: Invalid JSON or the property fileName
is missing
Body:
{
"message": "Unable to process the body. Please, review the content"
}
Status Code: 500
Reason: An error occurred with S3.
Body:
{
"message": "internal server error"
}
GET /audio/:filename
This route will return a S3 pre-signed URL, where you can download the file.
Request:
curl http://localhost:3000/audio/test
Expected responses:
Status: 200
Body:
{
"url": "http://aws.url"
}
Status Code: 400
Reason: The fileName
parameter is missing
Body:
{
"message": "Missing required parameter"
}
Status Code: 500
Reason: An error occurred with S3.
Body:
{
"message": "internal server error"
}
POST /metadata
This route will store the metadata related to a file stored in S3. The fileName
property should be stored on S3 with the same value and it is unique.
A body object is required, example:
{
"fileName": "test",
"author": "test",
"label": "test",
"type": "test",
"words": "test"
}
Request:
curl -X POST -H "Content-Type: application/json" -d '{
"fileName": "test",
"author": "test",
"label": "test",
"type": "test",
"words": "test"
}' http://localhost:3000/metadata
Expected responses:
Status: 201
Body:
{
"message": "successfully stored"
}
Status Code: 400
Reason: The request body probably has a bad syntax
Body:
{
"message": "Unable to process the body. Please, review the content"
}
Status Code: 400
Reason: Invalid type or field is missing on JSON property
Body:
{
"errors":[
{
"field":"Words",
"tag":"required",
"value":""
}
]
}
Status Code: 409
Reason: The metadata already exists on database
Body:
{
"message": "The object already exists"
}
Status Code: 422
Reason: The JSON fields and types are valid, but the audio is not on S3.
Body:
{
"message": "Filename not found. Unable to complete the operation"
}
Status Code: 500
Reason: An internal error happened.
Body:
{
"message": "internal server error"
}
GET /metadata
A body object is required, example:This route will list all metadata stored on dynamoDB.
Request:
curl http://localhost:3000/metadata
Expected responses:
Status: 200
Body:
{
"metadata":[
{
"filename":"test",
"author":"test",
"label":"test",
"type":"string",
"words":"test"
}
]
}
Status Code: 500
Reason: An internal error happened.
Body:
{
"message": "internal server error"
}