How do I setup AWS SDK credentials and region?

Sparta relies on standard AWS SDK configuration settings. See the official documentation for more information.

During development, configuration is typically done through environment variables:


What flags are defined during AWS AMI compilation?

  • TAGS: -tags lambdabinary

What working directory should I use?

Your working directory should be the root of your Sparta application. Eg, use

go run main.go provision --level info --s3Bucket $S3_BUCKET

rather than

go run ./some/child/path/main.go provision --level info --s3Bucket $S3_BUCKET

See GitHub for more details.

How can I test locally?

Local testing is available via the explore command.

Event Sources - SES

Where does the SpartaRuleSet come from?

SES only permits a single active receipt rule. Additionally, it’s possible that multiple Sparta-based services are handing different SES recipients.

All Sparta-based services share the SpartaRuleSet SES ruleset, and uniquely identify their Rules by including the current servicename as part of the SES ReceiptRule.

Why does provision not always enable the SpartaRuleSet?

Initial SpartaRuleSet will make it the active ruleset, but Sparta assumes that manual updates made outside of the context of the framework were done with good reason and doesn’t attempt to override the user setting.


How can I monitor my Lambda function?

If you plan on using your Lambdas in production, you’ll probably want to be made aware of any excessive errors.

You can easily do this by adding a CloudWatch alarm to your Lambda, in the decorator method.

This example will push a notification to an SNS topic, and you can configure whatever action is appropriate from there.

func lambdaDecorator(serviceName string,
	lambdaResourceName string,
	lambdaResource gocf.LambdaFunction,
	resourceMetadata map[string]interface{},
	S3Bucket string,
	S3Key string,
	buildID string,
	cfTemplate *gocf.Template,
	context map[string]interface{},
	logger *logrus.Logger) error {

	// setup CloudWatch alarm
	var alarmDimensions gocf.CloudWatchMetricDimensionList
	alarmDimension := gocf.CloudWatchMetricDimension{Name: gocf.String("FunctionName"), Value: gocf.Ref(lambdaResourceName).String()}
	alarmDimensions = []gocf.CloudWatchMetricDimension{alarmDimension}

	lambdaErrorsAlarm := &gocf.CloudWatchAlarm{
		ActionsEnabled:     gocf.Bool(true),
		AlarmActions:       gocf.StringList(gocf.String("arn:aws:sns:us-east-1:123456789:SNSToNotifyMe")),
		AlarmName:          gocf.String("LambdaErrorAlarm"),
		ComparisonOperator: gocf.String("GreaterThanOrEqualToThreshold"),
		Dimensions:         &alarmDimensions,
		EvaluationPeriods:  gocf.String("1"),
		Period:             gocf.String("300"),
		MetricName:         gocf.String("Errors"),
		Namespace:          gocf.String("AWS/Lambda"),
		Statistic:          gocf.String("Sum"),
		Threshold:          gocf.String("3.0"),
		Unit:               gocf.String("Count"),
	cfTemplate.AddResource("LambdaErrorAlaram", lambdaErrorsAlarm)

	return nil

Where can I view my function’s *logger output?

Each lambda function includes privileges to write to CloudWatch Logs. The *logrus.logger output is written (with a brief delay) to a lambda-specific log group.

The CloudWatch log group name includes a sanitized version of your Go function name & owning service name.

Where can I view Sparta’s golang spawn metrics?

Visit the CloudWatch Metrics AWS console page and select the Sparta/{SERVICE_NAME} namespace:


Sparta publishes two counters:

  • ProcessSpawned: A new Go process was spawned to handle requests
  • ProcessReused: An existing Go process was used to handle requests. See also the discussion on AWS Lambda container reuse.

How can I include additional AWS resources as part of my Sparta application?

Define a TemplateDecorator function and annotate the *gocf.Template with additional AWS resources.

For more flexibility, use a WorkflowHook.

How can I provide environment variables to lambda functions?

Sparta uses conditional compilation rather than environment variables. See Managing Environments for more information.

Does Sparta support Versioning & Aliasing?


Define a TemplateDecorator function and annotate the *gocf.Template with an AutoIncrementingLambdaVersionInfo resource. During each provision operation, the AutoIncrementingLambdaVersionInfo resource will dynamically update the CloudFormation template with a new version.

autoIncrementingInfo, autoIncrementingInfoErr := spartaCF.AddAutoIncrementingLambdaVersionResource(serviceName,

You can also move the “alias pointer” by referencing one or more of the versions available in the returned struct. For example, to set the alias pointer to the most recent version:

// Add an alias to the version we're publishing as part of this `provision` operation
aliasResourceName := sparta.CloudFormationResourceName("Alias", lambdaResourceName)
aliasResource := &gocf.LambdaAlias{
    Name:            gocf.String("MostRecentVersion"),
    FunctionName:    gocf.Ref(lambdaResourceName).String(),
    FunctionVersion: gocf.GetAtt(autoIncrementingInfo.CurrentVersionResourceName, "Version").String(),
cfTemplate.AddResource(aliasResourceName, aliasResource)

How do I forward additional metrics?

Sparta-deployed AWS Lambda functions always operate with CloudWatch Metrics putMetric privileges. Your lambda code can call putMetric with application-specific data.

How do I setup alerts on additional metrics?

Define a TemplateDecorator function and annotate the *gocf.Template with the needed AWS::CloudWatch::Alarm values. Use CloudFormationResourceName(prefix, …parts) to help generate unique resource names.

How can I determine the outputs available in sparta.Discover() for dynamic AWS resources?

The list of registered output provider types is defined by cloudformationTypeMapDiscoveryOutputs in cloudformation_resources.go. See the CloudFormation Resource Types Reference for information on interpreting the values.