aws-exec

aws-exec

Just ship services on AWS

github.com/nathants/aws-exec

Why

So you can just ship services on AWS.

What

A project scaffold for a backend service on AWS with an infrastructure set ready-to-deploy with libaws.

The project scaffold makes it easy to:

How

Synchronous APIs are normal HTTP on Lambda.

Asynchronous APIs are a HTTP POST that triggers an async Lambda which invokes a command via rpc or subprocess and stores the results in S3.

There are three ways to invoke an asynchronous API:

Add a New Synchronous Functionality

Add to api/.

Duplicate the httpExecGet or httpExecPost handler and modify it to introduce new functionality.

Add a New Asynchronous Functionality

Add to cmd/.

Duplicate the listdir command and modify it to introduce new functionality.

Web Demo

CLI Demo

API Demo

Mobile Demo

Dependencies

Use the included Dockerfile or install the following dependencies:

AWS Prerequisites

Usage

go install github.com/nathants/libaws@latest
export PATH=$PATH:$(go env GOPATH)/bin

cp env.sh.template env.sh # update values
bash bin/check.sh env.sh         # lint
bash bin/preview.sh env.sh       # preview changes to aws infra
bash bin/ensure.sh env.sh        # ensure aws infra
bash bin/dev.sh env.sh           # iterate on backend and frontend
bash bin/logs.sh env.sh          # tail the logs
bash bin/delete.sh env.sh        # delete aws infra
bash bin/cli.sh env.sh -h        # interact with the service via the cli

Usage with Docker

cp env.sh.template env.sh # update values
docker build -t aws-exec:latest .
docker run -it --rm \
    -v $(pwd):/code \
    -e AWS_DEFAULT_REGION \
    -e AWS_ACCESS_KEY_ID \
    -e AWS_SECRET_ACCESS_KEY \
    aws-exec:latest \
    bash -c '
        cd /code
        bash bin/ensure.sh
    '

Create Auth

bash bin/cli.sh env.sh auth-new test-user

Install and Use CLI

go install github.com/nathants/aws-exec@latest
export PATH=$PATH:$(go env GOPATH)/bin

export AUTH=$AUTH
export PROJECT_DOMAIN=$DOMAIN
aws-exec exec -- whoami

Install and Use API

go get github.com/nathants/aws-exec@latest
package cmd

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	awsexec "github.com/nathants/aws-exec/exec"
)

func main() {
	val, err := json.Marshal(map[string]any{
		"path": ".",
	})
	if err != nil {
	    panic(err)
	}
	exitCode, err := awsexec.Exec(context.Background(), &awsexec.Args{
		Url:     "https://%s" + os.Getenv("PROJECT_DOMAIN"),
		Auth:    os.Getenv("AUTH"),
		RpcName: "listdir",
		RpcArgs: string(val),
		LogDataCallback: func(logs string) {
			fmt.Print(logs)
		},
	})
	if err != nil {
		panic(err)
	}
	os.Exit(exitCode)
}