Sparta: Index | Examples | Files

package decorator

import ""

Package decorator exposes Sparta decorator types to mutate the CloudFormation template



Package Files

alarm.go apigateway_domain.go dashboard.go distribution.go doc.go log_aggregator.go outputs.go s3_artifact_publisher.go safe_deploy.go versioning.go


const (
    // APIGatewayMappingEntry is the keyname used to store the API Gateway mappings
    APIGatewayMappingEntry = "APIGatewayMappings"
const (
    // OutputDashboardURL is the keyname used in the CloudFormation Output
    // that stores the CloudWatch Dashboard URL
    // @enum OutputKey
    OutputDashboardURL = "CloudWatchDashboardURL"


var LogAggregatorAssumePolicyDocument = sparta.ArbitraryJSONObject{
    "Version": "2012-10-17",
    "Statement": []sparta.ArbitraryJSONObject{
            "Action": []string{"sts:AssumeRole"},
            "Effect": "Allow",
            "Principal": sparta.ArbitraryJSONObject{
                "Service": []string{

LogAggregatorAssumePolicyDocument is the document for LogSubscription filters

func APIGatewayDomainDecorator Uses

func APIGatewayDomainDecorator(apiGateway *sparta.API,
    acmCertARN gocf.Stringable,
    basePath string,
    domainName string) sparta.ServiceDecoratorHookHandler

APIGatewayDomainDecorator returns a ServiceDecoratorHookHandler implementation that registers a custom domain for an API Gateway service


helloWorld := func(ctx context.Context,
    gatewayEvent spartaAWSEvents.APIGatewayRequest) (interface{}, error) {
    return "Hello World", nil
lambdaFuncs := func(api *sparta.API) []*sparta.LambdaAWSInfo {
    var lambdaFunctions []*sparta.LambdaAWSInfo
    lambdaFn := sparta.HandleAWSLambda(sparta.LambdaName(helloWorld),
    apiGatewayResource, _ := api.NewResource("/hello", lambdaFn)

    // We only return http.StatusOK
    apiMethod, apiMethodErr := apiGatewayResource.NewMethod("GET",
    if nil != apiMethodErr {
        panic("Failed to create /hello resource: " + apiMethodErr.Error())
    // The lambda resource only supports application/json Unmarshallable
    // requests.
    apiMethod.SupportedRequestContentTypes = []string{"application/json"}
    return append(lambdaFunctions, lambdaFn)

apigatewayHooks := func(apiGateway *sparta.API) *sparta.WorkflowHooks {
    hooks := &sparta.WorkflowHooks{}

    serviceDecorator := APIGatewayDomainDecorator(apiGateway,
        "", // Optional base path value
    hooks.ServiceDecorators = []sparta.ServiceDecoratorHookHandler{
    return hooks

// Register the function with the API Gateway
apiStage := sparta.NewStage("v1")

apiGateway := sparta.NewAPIGateway("SpartaHTMLDomain", apiStage)
apiGateway.EndpointConfiguration = &gocf.APIGatewayRestAPIEndpointConfiguration{
    Types: gocf.StringList(
hooks := apigatewayHooks(apiGateway)
// Deploy it
stackName := spartaCF.UserScopedStackName("CustomAPIGateway")
    fmt.Sprintf("CustomAPIGateway defines a stack with a custom APIGateway Domain Name"),

func CloudFrontSiteDistributionDecorator Uses

func CloudFrontSiteDistributionDecorator(s3Site *sparta.S3Site,
    subdomain string,
    domainName string,
    acmCertificateARN gocf.Stringable) sparta.ServiceDecoratorHookHandler

CloudFrontSiteDistributionDecorator returns a ServiceDecoratorHookHandler function that provisions a CloudFront distribution whose origin is the supplied S3Site bucket. If the acmCertificateARN value is non-nil, the CloudFront distribution will support SSL access via the ViewerCertificate struct

func CloudWatchErrorAlarmDecorator Uses

func CloudWatchErrorAlarmDecorator(periodWindow int,
    minutesPerPeriod int,
    thresholdGreaterThanOrEqualToValue int,
    snsTopic gocf.Stringable) sparta.TemplateDecoratorHookFunc

CloudWatchErrorAlarmDecorator returns a TemplateDecoratorHookFunc that associates a CloudWatch Lambda Error count alarm with the given lambda function. The four parameters are periodWindow, minutes per period the strict lower bound value, and the SNS topic to which alerts should be sent. See the CloudWatch alarm resource type in the official AWS documentation at for more information

func CodeDeployServiceUpdateDecorator Uses

func CodeDeployServiceUpdateDecorator(updateType string,
    lambdaFuncs []*sparta.LambdaAWSInfo,
    preHook *sparta.LambdaAWSInfo,
    postHook *sparta.LambdaAWSInfo) sparta.ServiceDecoratorHookFunc

CodeDeployServiceUpdateDecorator is a service level decorator that attaches the CodeDeploy safe update to an upgrade operation. Ref:

func DashboardDecorator Uses

func DashboardDecorator(lambdaAWSInfo []*sparta.LambdaAWSInfo,
    timeSeriesPeriod int) sparta.ServiceDecoratorHookFunc

DashboardDecorator returns a ServiceDecoratorHook function that can be attached the workflow to create a dashboard

func LambdaVersioningDecorator Uses

func LambdaVersioningDecorator() sparta.TemplateDecoratorHookFunc

LambdaVersioningDecorator returns a TemplateDecorator that is responsible for including a versioning resource with the given lambda function

func PublishAllResourceOutputs Uses

func PublishAllResourceOutputs(cfResourceName string,
    cfResource gocf.ResourceProperties) sparta.ServiceDecoratorHookFunc

PublishAllResourceOutputs is a utility function to include all Ref and Att outputs associated with the given (cfResourceName, cfResource) pair.

func PublishAttOutputDecorator Uses

func PublishAttOutputDecorator(keyName string, description string, fieldName string) sparta.TemplateDecoratorHookFunc

PublishAttOutputDecorator returns a TemplateDecoratorHookFunc that publishes an Att value for a given Lambda

func PublishRefOutputDecorator Uses

func PublishRefOutputDecorator(keyName string, description string) sparta.TemplateDecoratorHookFunc

PublishRefOutputDecorator returns an TemplateDecoratorHookFunc that publishes the Ref value for a given lambda

func S3ArtifactPublisherDecorator Uses

func S3ArtifactPublisherDecorator(bucket gocf.Stringable,
    key gocf.Stringable,
    data map[string]interface{}) sparta.ServiceDecoratorHookHandler

S3ArtifactPublisherDecorator returns a ServiceDecoratorHookHandler function that publishes the given data to an S3 Bucket using the given bucket and key.

type DashboardTemplateData Uses

type DashboardTemplateData struct {
    // The list of lambda functions
    LambdaFunctions []*LambdaTemplateData
    // SpartaVersion is the Sparta library used to provision this service
    SpartaVersion string
    // SpartaGitHash is the commit hash of this version of the library
    SpartaGitHash    string
    TimeSeriesPeriod int
    Extents          widgetExtents

DashboardTemplateData is the object supplied to the dashboard template to generate the resulting dashboard

type LambdaTemplateData Uses

type LambdaTemplateData struct {
    LambdaAWSInfo *sparta.LambdaAWSInfo
    ResourceName  string

LambdaTemplateData is the mapping of Sparta public LambdaAWSInfo together with the CloudFormationResource name this resource uses

type LogAggregatorDecorator Uses

type LogAggregatorDecorator struct {
    // contains filtered or unexported fields

LogAggregatorDecorator is the decorator that satisfies both the ServiceDecoratorHandler and TemplateDecoratorHandler interfaces. It ensures that each lambda function has a CloudWatch logs subscription that forwards to a Kinesis stream. That stream is then subscribed to by the relay lambda function. Only log statements of level info or higher are published to Kinesis.

func NewLogAggregatorDecorator Uses

func NewLogAggregatorDecorator(
    kinesisResource *gocf.KinesisStream,
    kinesisMapping *sparta.EventSourceMapping,
    relay *sparta.LambdaAWSInfo) *LogAggregatorDecorator

NewLogAggregatorDecorator returns a ServiceDecoratorHook that registers a Kinesis stream lambda log aggregator

func (*LogAggregatorDecorator) DecorateService Uses

func (lad *LogAggregatorDecorator) DecorateService(context map[string]interface{},
    serviceName string,
    template *gocf.Template,
    S3Bucket string,
    S3Key string,
    buildID string,
    awsSession *session.Session,
    noop bool,
    logger *logrus.Logger) error

DecorateService annotates the service with the Kinesis hook

func (*LogAggregatorDecorator) DecorateTemplate Uses

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

DecorateTemplate annotates the lambda with the log forwarding sink info

func (*LogAggregatorDecorator) KinesisLogicalResourceName Uses

func (lad *LogAggregatorDecorator) KinesisLogicalResourceName() string

KinesisLogicalResourceName returns the name of the Kinesis stream that will be provisioned by this Decorator

Package decorator imports 15 packages (graph). Updated 2019-02-17. Refresh now. Tools for package owners.