Skip to content

Files

Latest commit

cdf5c42 · Aug 29, 2023

History

History
58 lines (43 loc) · 1.22 KB

README.md

File metadata and controls

58 lines (43 loc) · 1.22 KB

SST Resource Binding for Go

SST lets you bind resources to Lambda functions which both adds the right permissions and also injects environment variables containing information about that resource, for example it's ARN.

This package is a port of the node package for using resource bindng in Lambda functions written in Go.

Simple Example

If you have an S3 bucket that is bound to a function:

// Create an S3 bucket
const bucket = new Bucket(stack, "MyFiles");

new Function(stack, "MyFunction", {
  handler: "main.go",
  // Bind to function
  bind: [bucket],
});

Then in your Go function you can access the bucket name by doing the following:

package main

import (
    "fmt"

    "github.com/aws/aws-lambda-go/lambda"
    "github.com/teamkeel/sst-go"
)

func main() {
    lambda.Start(handler)
}

func handler(ctx context.Context) error {
    // load the resource
    bucket, err := sst.Bucket("MyFiles")
    if err != nil {
      return err
    }

    bucket.BucketName // name of the bucket
}

Supported Bindings

  • Secret (including fallback values)
  • Parameter
  • Function
  • EventBus
  • Topic
  • Queue
  • RDS
  • Table