github.com/mweagle/Sparta@v1.15.0/doc_newmains3site_test.go (about)

     1  package sparta
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/aws/aws-lambda-go/lambdacontext"
     8  	"github.com/sirupsen/logrus"
     9  )
    10  
    11  // NOTE: your application MUST use `package main` and define a `main()` function.  The
    12  // example text is to make the documentation compatible with godoc.
    13  
    14  func echoS3SiteAPIGatewayEvent(ctx context.Context,
    15  	props map[string]interface{}) (map[string]interface{}, error) {
    16  	lambdaCtx, _ := lambdacontext.FromContext(ctx)
    17  	Logger().WithFields(logrus.Fields{
    18  		"RequestID":  lambdaCtx.AwsRequestID,
    19  		"Properties": props,
    20  	}).Info("Lambda event")
    21  	return props, nil
    22  }
    23  
    24  // Should be main() in your application
    25  func ExampleMain_s3Site() {
    26  
    27  	// Create an API Gateway
    28  	apiStage := NewStage("v1")
    29  	apiGateway := NewAPIGateway("SpartaS3Site", apiStage)
    30  	apiGateway.CORSEnabled = true
    31  
    32  	// Create a lambda function
    33  	echoS3SiteAPIGatewayEventLambdaFn, _ := NewAWSLambda(LambdaName(echoS3SiteAPIGatewayEvent),
    34  		echoS3SiteAPIGatewayEvent,
    35  		IAMRoleDefinition{})
    36  	apiGatewayResource, _ := apiGateway.NewResource("/hello", echoS3SiteAPIGatewayEventLambdaFn)
    37  	_, err := apiGatewayResource.NewMethod("GET", http.StatusOK)
    38  	if nil != err {
    39  		panic("Failed to create GET resource")
    40  	}
    41  	// Create an S3 site from the contents in ./site
    42  	s3Site, _ := NewS3Site("./site")
    43  
    44  	// Provision everything
    45  	Main("HelloWorldS3SiteService", "Description for S3Site", []*LambdaAWSInfo{echoS3SiteAPIGatewayEventLambdaFn}, apiGateway, s3Site)
    46  }