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