Sparta: Index | Files

package s3

import ""

Package s3 provides types to support unmarshalling generic `event *json.RawMessage` types into S3 specific event structures. Sparta-based S3 event listeners can unmarshall the RawMesssage into source-specific data. Example:

func s3EventListener(event *json.RawMessage,
                      context *sparta.LambdaContext,
                      w http.ResponseWriter,
                      logger *logrus.Logger) {
  var lambdaEvent spartaS3.Event
  err := json.Unmarshal([]byte(*event), &lambdaEvent)
  if err != nil {
    logger.Error("Failed to unmarshal event data: ", err.Error())
    http.Error(w, err.Error(), http.StatusInternalServerError)
  for _, eachRecord := range lambdaEvent.Records {
    switch eachRecord.EventName {
      case "ObjectCreated:Put": {...}
      default : {...}


Package Files

doc.go events.go util.go

func BucketRegion Uses

func BucketRegion(awsSession *session.Session,
    S3Bucket string,
    logger *logrus.Logger) (string, error)

BucketRegion returns the AWS region that hosts the bucket

func BucketVersioningEnabled Uses

func BucketVersioningEnabled(awsSession *session.Session,
    S3Bucket string,
    logger *logrus.Logger) (bool, error)

BucketVersioningEnabled determines if a given S3 bucket has object versioning enabled.

func UploadLocalFileToS3 Uses

func UploadLocalFileToS3(localPath string,
    awsSession *session.Session,
    S3Bucket string,
    S3KeyName string,
    logger *logrus.Logger) (string, error)

UploadLocalFileToS3 takes a local path and uploads the content at localPath to the given S3Bucket and KeyPrefix. The final S3 keyname is the S3KeyPrefix+ the basename of the localPath.

type Bucket Uses

type Bucket struct {
    Name          string             `json:"name"`
    Arn           string             `json:"arn"`
    OwnerIdentity EventOwnerIdentity `json:"ownerIdentity"`

Bucket event data

type Event Uses

type Event struct {
    Records []EventRecord

Event data

type EventOwnerIdentity Uses

type EventOwnerIdentity struct {
    PrincpalID string `json:"principalId"`

EventOwnerIdentity event data

type EventRecord Uses

type EventRecord struct {
    Region       string `json:"awsRegion"`
    EventName    string `json:"eventName"`
    EventTime    string `json:"eventTime"`
    EventSource  string `json:"eventSource"`
    EventVersion string `json:"eventVersion"`
    S3           S3     `json:"s3"`

EventRecord event data

type Object Uses

type Object struct {
    Key       string `json:"key"`
    Sequencer string `json:"sequencer"`

Object event data

type RollbackFunction Uses

type RollbackFunction func(logger *logrus.Logger) error

RollbackFunction called in the event of a stack provisioning failure

func CreateS3RollbackFunc Uses

func CreateS3RollbackFunc(awsSession *session.Session, s3ArtifactURL string) RollbackFunction

CreateS3RollbackFunc creates an S3 rollback function that attempts to delete a previously uploaded item. Note that s3ArtifactURL may include a `versionId` query arg to denote the specific version to delete.

type S3 Uses

type S3 struct {
    SchemaVersion   string `json:"s3SchemaVersion"`
    ConfigurationID string `json:"configurationId"`
    Bucket          Bucket `json:"bucket"`
    Object          Object `json:"object"`

S3 event information

Package s3 imports 13 packages (graph) and is imported by 1 packages. Updated 2018-04-27. Refresh now. Tools for package owners.