Discover ways to construct a Golang Lambda service in a container, hook it as much as a REST API end-point, and push and pull information from S3.
The Objective of this Golang Lambda Challenge
Right here is the plan after I make a name like this:
>_curl https://earthly-tools.com/text-mode?url=https://www.lipsum.com/
It would 1) hit the API gateway, 2) name my GoLang lambda perform handler. My code will then 3) pull the positioning from the online and 4) clear it as much as seem like a textual content doc and return it to the person. Final we are going to deal with 5) including some caching into the combo.
However the finish result’s already up and working at https://earthly-tools.com/text-mode and can return one thing like this:
curl end resultWhat's Lorem Ipsum?
Lorem Ipsum is solely dummy textual content of the printing and typesetting
business. Lorem Ipsum has been the business's commonplace dummy textual content ever
for the reason that 1500s, when an unknown printer took a galley of kind and
scrambled it to make a sort specimen e-book. It has survived not solely
5 centuries, but in addition the leap into digital typesetting,
remaining basically unchanged. It was popularised within the Nineteen Sixties with
the discharge of Letraset sheets containing Lorem Ipsum passages, and
extra just lately with desktop publishing software program like Aldus PageMaker
together with variations of Lorem Ipsum.
...
And all in ~150 strains of Go code. So let’s do it.
The AWS Serverless REST API
When my Go Lambda is known as through the lambda runtime, it’ll get a JSON occasion describing the request it acquired:
pattern enter{
"queryStringParameters": {
"url": "https://www.lipsum.com/"
}
}
And, I’ll return an occasion describing the doc I’d like produced.
pattern output{
statusCode: 200,
headers: {
"content-type": "textual content/plain; charset=utf-8"
},
physique: "What's Lorem Ipsum?nn ..."
}
The entire thing has the texture of an old-fashion CGI Interface.
I characterize the enter JSON in Golang like this:
enter sortskind Occasion struct {
QueryStringParameters QueryStringParameters `json:"queryStringParameters"`
}
kind QueryStringParameters struct {
Url string `json:"url"`
}
And output like so:
output sortskind Response struct {
StatusCode int `json:"statusCode"`
Physique string `json:"physique"`
Headers map[string]string `json:"headers"`
}
And, with these in place, I can write my lambda handler code.