A Lambda function using the Go 1.x runtime that takes a list of URLs, archives the data from them in a zip file, and provides a download URL.
Install and use AWS SAM Local for local testing.
This will use the template.yml
file as a definition of the function to test.
- Start the local API:
sam local start-api
- Make changes to the code
- Build the code:
GOOS=linux GOARCH=amd64 go build -o main main.go
- Use the included Postman collection for testing requests against the code
- Archive the built artifact:
zip main.zip main
- Upload it to your Lambda function:
aws lambda update-function-code --function-name archive --zip-file fileb://main.zip
The request body takes a filename and array of URLs. The filename is used as the filename for anyone who downloads the archive file that is created from the files in the "urls" array.
curl -X POST \
http://127.0.0.1:3000/archive \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"filename": "randomImages",
"urls": [
"https://placeimg.com/640/480/any?1",
"https://placeimg.com/640/480/any?2",
"https://placeimg.com/640/480/any?3"
]
}'