github.com/mweagle/Sparta@v1.15.0/docs_source/content/getting_started/_index.md (about) 1 --- 2 date: 2019-11-27 16:12:19 3 title: Getting Started 4 description: Getting started with Sparta 5 weight: 5 6 alwaysopen: false 7 --- 8 9 To build a Sparta application, follow these steps: 10 11 1. `go get -u -v https://github.com/mweagle/Sparta/...` 12 2. Configure your AWS Credentials according to the [go SDK docs](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials). The most reliable approach is to use environment variables as in: 13 14 ```shell 15 $ env | grep AWS 16 AWS_DEFAULT_REGION=us-xxxx-x 17 AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 18 AWS_REGION=us-xxxx-x 19 AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxx 20 ``` 21 22 3. Create a sample _main.go_ file as in: 23 24 ```go 25 package main 26 27 import ( 28 "context" 29 "fmt" 30 "os" 31 32 "github.com/aws/aws-sdk-go/aws/session" 33 sparta "github.com/mweagle/Sparta" 34 spartaCF "github.com/mweagle/Sparta/aws/cloudformation" 35 "github.com/sirupsen/logrus" 36 ) 37 38 // Standard AWS λ function 39 40 func helloWorld(ctx context.Context) (string, error) { 41 logger, loggerOk := ctx.Value(sparta.ContextKeyLogger).(*logrus.Logger) 42 if loggerOk { 43 logger.Info("Accessing structured logger 🙌") 44 } 45 return "Hello World 👋. Welcome to AWS Lambda! 🙌🎉🍾", nil 46 } 47 48 //////////////////////////////////////////////////////////////////////////////// 49 // Main 50 func main() { 51 lambdaFn, _ := sparta.NewAWSLambda("Hello World", 52 helloWorld, 53 sparta.IAMRoleDefinition{}) 54 55 sess := session.Must(session.NewSession()) 56 awsName, awsNameErr := spartaCF.UserAccountScopedStackName("MyHelloWorldStack", 57 sess) 58 if awsNameErr != nil { 59 fmt.Print("Failed to create stack name\n") 60 os.Exit(1) 61 } 62 var lambdaFunctions []*sparta.LambdaAWSInfo 63 lambdaFunctions = append(lambdaFunctions, lambdaFn) 64 65 err := sparta.Main(awsName, 66 "Simple Sparta HelloWorld application", 67 lambdaFunctions, 68 nil, 69 nil) 70 if err != nil { 71 os.Exit(1) 72 } 73 } 74 ``` 75 76 4. Build with `go run main.go provision --s3Bucket YOUR_S3_BUCKET_NAME` where `YOUR_S3_BUCKET_NAME` is an S3 bucket to which your account has write privileges. 77 78 The following [Example Service](/example_service) section provides more details regarding how Sparta transforms your application into a self-deploying service.