Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
Resources:
HelloGopher: # Here we set a Resource Name, You can set anything you want.
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: ./ # This is the path to the Code, in our case we are bad and store it in root
Handler: hello-gopher
Runtime: go1.x
Environment:
Variables:
my-cool-variable: "maybe-not-so-cool"
package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
demo
Sample SAM Template for demo
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
sam local invoke -e event.json
Invoking hello-gopher (go1.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-go1.x:rapid-1.40.1-x86_64.
Mounting /home/percy/development/aws-sam-demo/demo/.aws-sam/build/HelloGopher as /var/task:ro,delegated inside runtime container
START RequestId: 50c407a8-9a71-4acc-a45b-2ad1d725c759 Version: $LATEST
END RequestId: 50c407a8-9a71-4acc-a45b-2ad1d725c759
REPORT RequestId: 50c407a8-9a71-4acc-a45b-2ad1d725c759 Init Duration: 0.21 ms Duration: 36.67 ms Billed Duration: 37 ms Memory Size: 128 MB Max Memory Used: 128 MB
"Hello From Lambda Percy"
{
"name": "Percy"
}
sam local invoke
Invoking hello-gopher (go1.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-go1.x:rapid-1.40.1-x86_64.
Mounting /home/percy/development/aws-sam-demo/demo as /var/task:ro,delegated inside runtime container
START RequestId: 10b09db1-9b02-4e1b-9b39-ce410039bfc1 Version: $LATEST
fork/exec /var/task/hello-gopher: no such file or directory: PathError
null
END RequestId: 10b09db1-9b02-4e1b-9b39-ce410039bfc1
REPORT RequestId: 10b09db1-9b02-4e1b-9b39-ce410039bfc1 Init Duration: 0.15 ms Duration: 29.82 ms Billed Duration: 30 ms Memory Size: 128 MB Max Memory Used: 128 MB
@percybolmer
percybolmer / Sam-Simplest-Templaet.yml
Last active March 30, 2022 18:13
A simple SAM template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
demo
Sample SAM Template for demo
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
@percybolmer
percybolmer / AWS-Sam-Simple-Lambda.go
Created March 22, 2022 19:10
The simplest lambda in go
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
)
// Event is the Input Payload representation
type Event struct {
// Wget to Fetch ZIP
wget https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
// Unzip into a folder named sam-installation
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
// Execute installation script
sudo ./sam-installation/install
// Cleanup
rm -rf aws-sam-cli-linux-x86_64.zip
rm -rf sam-installation
@percybolmer
percybolmer / LD Flags main-v2.go
Last active March 8, 2022 19:23
LD flags with the new build package in the main
package main
import (
"log"
"programmingpercy.tech/buildflags/version"
)
var (
runner = "client-1.0.0"
)