Documentation ¶
Overview ¶
Package decorator exposes Sparta decorator types to mutate the CloudFormation template
Index ¶
- Constants
- Variables
- func APIGatewayDomainDecorator(apiGateway *sparta.API, acmCertARN string, basePath string, domainName string) sparta.ServiceDecoratorHookHandler
- func CloudFrontSiteDistributionDecorator(s3Site *sparta.S3Site, subdomain string, domainName string, ...) sparta.ServiceDecoratorHookHandler
- func CloudFrontSiteDistributionDecoratorWithCert(s3Site *sparta.S3Site, subdomain string, domainName string, ...) sparta.ServiceDecoratorHookHandler
- func CloudWatchErrorAlarmDecorator(periodWindow int, minutesPerPeriod int, ...) sparta.TemplateDecoratorHookFunc
- func CodeDeployServiceUpdateDecorator(updateType string, lambdaFuncs []*sparta.LambdaAWSInfo, ...) sparta.ServiceDecoratorHookFunc
- func DashboardDecorator(lambdaAWSInfo []*sparta.LambdaAWSInfo, timeSeriesPeriod int) sparta.ServiceDecoratorHookFunc
- func DiscoverInstances(ctx context.Context, attributes map[string]string, logger *zerolog.Logger) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
- func DiscoverInstancesInServiceWithContext(ctx context.Context, namespaceName string, serviceName string, ...) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
- func DiscoverInstancesWithContext(ctx context.Context, attributes map[string]string, logger *zerolog.Logger) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
- func LambdaVersioningDecorator() sparta.TemplateDecoratorHookFunc
- func PublishAllResourceOutputs(cfResourceName string, cfResource gof.Resource) sparta.ServiceDecoratorHookFunc
- func PublishAttOutputDecorator(keyName string, description string, fieldName string) sparta.TemplateDecoratorHookFunc
- func PublishRefOutputDecorator(keyName string, description string) sparta.TemplateDecoratorHookFunc
- func ResourceDecorator(resources map[string]gof.Resource) sparta.ServiceDecoratorHookFunc
- func S3ArtifactPublisherDecorator(bucket string, key string, data map[string]interface{}) sparta.ServiceDecoratorHookHandler
- type ApplicationLoadBalancerDecorator
- func (albd *ApplicationLoadBalancerDecorator) AddConditionalEntry(condition gofelbv2.ListenerRule_RuleCondition, lambdaFn *sparta.LambdaAWSInfo) *ApplicationLoadBalancerDecorator
- func (albd *ApplicationLoadBalancerDecorator) AddConditionalEntryWithPriority(condition gofelbv2.ListenerRule_RuleCondition, priority int, ...) *ApplicationLoadBalancerDecorator
- func (albd *ApplicationLoadBalancerDecorator) AddMultiConditionalEntry(conditions []gofelbv2.ListenerRule_RuleCondition, ...) *ApplicationLoadBalancerDecorator
- func (albd *ApplicationLoadBalancerDecorator) AddMultiConditionalEntryWithPriority(conditions []gofelbv2.ListenerRule_RuleCondition, priority int, ...) *ApplicationLoadBalancerDecorator
- func (albd *ApplicationLoadBalancerDecorator) DecorateService(context map[string]interface{}, serviceName string, template *gof.Template, ...) error
- func (albd *ApplicationLoadBalancerDecorator) LogicalResourceName() string
- type CloudMapServiceDecorator
- func (cmsd *CloudMapServiceDecorator) DecorateService(context map[string]interface{}, serviceName string, template *gof.Template, ...) error
- func (cmsd *CloudMapServiceDecorator) EnableDiscoverySupport(lambdaInfo *sparta.LambdaAWSInfo, additionalServiceIDs ...string) error
- func (cmsd *CloudMapServiceDecorator) LogicalResourceName() string
- func (cmsd *CloudMapServiceDecorator) PublishLambda(lookupName string, lambdaInfo *sparta.LambdaAWSInfo, ...) error
- func (cmsd *CloudMapServiceDecorator) PublishResource(lookupName string, resourceName string, resource gof.Resource, ...) error
- type DashboardTemplateData
- type LambdaTemplateData
- type LogAggregatorDecorator
- func (lad *LogAggregatorDecorator) DecorateService(ctx context.Context, serviceName string, template *gof.Template, ...) (context.Context, error)
- func (lad *LogAggregatorDecorator) DecorateTemplate(ctx context.Context, serviceName string, lambdaResourceName string, ...) (context.Context, error)
- func (lad *LogAggregatorDecorator) KinesisLogicalResourceName() string
Examples ¶
Constants ¶
const ( // KeyCloudMapRef is the name of the property that contains the `Ref` // output from the CloudFormation resource KeyCloudMapRef = "Ref" // KeyCloudMapType is the name of the property that contains the CloudFormation // resource type of the published resource KeyCloudMapType = "Type" // KeyCloudMapResourceName is the logical CloudFormation resource name KeyCloudMapResourceName = "ResourceName" )
const ( // EnvVarCloudMapNamespaceID contains the CloudMap namespaceID that was // registered in this stack. This serviceID enables your lambda function // to call the https://docs.aws.amazon.com/sdk-for-go/api/service/servicediscovery // for listing or discovering instanes EnvVarCloudMapNamespaceID = "SPARTA_CLOUDMAP_NAMESPACE_ID" // EnvVarCloudMapServiceID contains the CloudMap serviceID that was // registered in this stack. This serviceID enables your lambda function // to call the https://docs.aws.amazon.com/sdk-for-go/api/service/servicediscovery // for listing or discovering instanes EnvVarCloudMapServiceID = "SPARTA_CLOUDMAP_SERVICE_ID" )
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" )
Variables ¶
var LogAggregatorAssumePolicyDocument = sparta.ArbitraryJSONObject{ "Version": "2012-10-17", "Statement": []sparta.ArbitraryJSONObject{ { "Action": []string{"sts:AssumeRole"}, "Effect": "Allow", "Principal": sparta.ArbitraryJSONObject{ "Service": []string{ "logs.us-west-2.amazonaws.com", }, }, }, }, }
LogAggregatorAssumePolicyDocument is the document for LogSubscription filters
Functions ¶
func APIGatewayDomainDecorator ¶
func APIGatewayDomainDecorator(apiGateway *sparta.API, acmCertARN string, basePath string, domainName string) sparta.ServiceDecoratorHookHandler
APIGatewayDomainDecorator returns a ServiceDecoratorHookHandler implementation that registers a custom domain for an API Gateway service
Example ¶
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.NewAWSLambda(sparta.LambdaName(helloWorld), helloWorld, sparta.IAMRoleDefinition{}) apiGatewayResource, _ := api.NewResource("/hello", lambdaFn) // We only return http.StatusOK apiMethod, apiMethodErr := apiGatewayResource.NewMethod("GET", http.StatusOK, http.StatusInternalServerError) 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, "arn:aws:acm:us-west-2:123412341234:certificate/6486C3FF-A3B7-46B6-83A0-9AE329FEC4E3", "", // Optional base path value "noice.spartademo.net") hooks.ServiceDecorators = []sparta.ServiceDecoratorHookHandler{ serviceDecorator, } return hooks } // Register the function with the API Gateway apiStage := sparta.NewStage("v1") apiGateway := sparta.NewAPIGateway("SpartaHTMLDomain", apiStage) apiGateway.EndpointConfiguration = &gofapig.RestApi_EndpointConfiguration{ Types: []string{"REGIONAL"}, } hooks := apigatewayHooks(apiGateway) // Deploy it stackName := spartaCF.UserScopedStackName("CustomAPIGateway") mainErr := sparta.MainEx(stackName, "CustomAPIGateway defines a stack with a custom APIGateway Domain Name", lambdaFuncs(apiGateway), apiGateway, nil, hooks, false) if mainErr != nil { panic("Failed to launch Main: " + mainErr.Error()) }
Output:
func CloudFrontSiteDistributionDecorator ¶
func CloudFrontSiteDistributionDecorator(s3Site *sparta.S3Site, subdomain string, domainName string, acmCertificateARN string) sparta.ServiceDecoratorHookHandler
CloudFrontSiteDistributionDecorator returns a CloudFrontSiteDecorator with the default VIP certificate. NOTE: The default VIP certificate is expensive. Consider using SNI to reduce costs. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-viewercertificate.html#cfn-cloudfront-distribution-viewercertificate-sslsupportmethod for more information.
func CloudFrontSiteDistributionDecoratorWithCert ¶
func CloudFrontSiteDistributionDecoratorWithCert(s3Site *sparta.S3Site, subdomain string, domainName string, cert *gofCloudFront.Distribution_ViewerCertificate) sparta.ServiceDecoratorHookHandler
CloudFrontSiteDistributionDecoratorWithCert returns a ServiceDecoratorHookHandler function that provisions a CloudFront distribution whose origin is the supplied S3Site bucket. The supplied viewer certificate allows customization of the CloudFront Distribution SSL options. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-viewercertificate.html for more information.
func CloudWatchErrorAlarmDecorator ¶
func CloudWatchErrorAlarmDecorator(periodWindow int, minutesPerPeriod int, thresholdGreaterThanOrEqualToValue float64, snsTopic string) 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 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html for more information
func CodeDeployServiceUpdateDecorator ¶
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: https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst
func DashboardDecorator ¶
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 DiscoverInstances ¶
func DiscoverInstances(ctx context.Context, attributes map[string]string, logger *zerolog.Logger) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
DiscoverInstances returns the HttpInstanceSummary items that match the given attribute map
func DiscoverInstancesInServiceWithContext ¶
func DiscoverInstancesInServiceWithContext(ctx context.Context, namespaceName string, serviceName string, attributes map[string]string, logger *zerolog.Logger) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
DiscoverInstancesInServiceWithContext returns the HttpInstanceSummary items that match the given attribute map using the supplied context and within the given ServiceID
func DiscoverInstancesWithContext ¶
func DiscoverInstancesWithContext(ctx context.Context, attributes map[string]string, logger *zerolog.Logger) ([]awsv2ServiceDiscoveryTypes.HttpInstanceSummary, error)
DiscoverInstancesWithContext returns the HttpInstanceSummary items that match the given attribute map for the default service provisioned with this application
func LambdaVersioningDecorator ¶
func LambdaVersioningDecorator() sparta.TemplateDecoratorHookFunc
LambdaVersioningDecorator returns a TemplateDecorator that is responsible for including a versioning resource with the given lambda function
func PublishAllResourceOutputs ¶
func PublishAllResourceOutputs(cfResourceName string, cfResource gof.Resource) sparta.ServiceDecoratorHookFunc
PublishAllResourceOutputs is a utility function to include all Ref and Att outputs associated with the given (cfResourceName, cfResource) pair.
func PublishAttOutputDecorator ¶
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 ¶
func PublishRefOutputDecorator(keyName string, description string) sparta.TemplateDecoratorHookFunc
PublishRefOutputDecorator returns an TemplateDecoratorHookFunc that publishes the Ref value for a given lambda
func ResourceDecorator ¶
func ResourceDecorator(resources map[string]gof.Resource) sparta.ServiceDecoratorHookFunc
ResourceDecorator is a convenience function to insert a map of resources into the template.
func S3ArtifactPublisherDecorator ¶
func S3ArtifactPublisherDecorator(bucket string, key string, 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.
Types ¶
type ApplicationLoadBalancerDecorator ¶
type ApplicationLoadBalancerDecorator struct { Resources map[string]gof.Resource // contains filtered or unexported fields }
ApplicationLoadBalancerDecorator is an instance of a service decorator that handles registering Lambda functions with an Application Load Balancer.
func NewApplicationLoadBalancerDecorator ¶
func NewApplicationLoadBalancerDecorator(alb *gofelbv2.LoadBalancer, port int, protocol string, defaultLambdaHandler *sparta.LambdaAWSInfo) (*ApplicationLoadBalancerDecorator, error)
NewApplicationLoadBalancerDecorator returns an application load balancer decorator that allows one or more lambda functions to be marked as ALB targets
func (*ApplicationLoadBalancerDecorator) AddConditionalEntry ¶
func (albd *ApplicationLoadBalancerDecorator) AddConditionalEntry(condition gofelbv2.ListenerRule_RuleCondition, lambdaFn *sparta.LambdaAWSInfo) *ApplicationLoadBalancerDecorator
AddConditionalEntry adds a new lambda target that is conditionally routed to depending on the condition value.
func (*ApplicationLoadBalancerDecorator) AddConditionalEntryWithPriority ¶
func (albd *ApplicationLoadBalancerDecorator) AddConditionalEntryWithPriority(condition gofelbv2.ListenerRule_RuleCondition, priority int, lambdaFn *sparta.LambdaAWSInfo) *ApplicationLoadBalancerDecorator
AddConditionalEntryWithPriority adds a new lambda target that is conditionally routed to depending on the condition value using the user supplied priority value
func (*ApplicationLoadBalancerDecorator) AddMultiConditionalEntry ¶
func (albd *ApplicationLoadBalancerDecorator) AddMultiConditionalEntry(conditions []gofelbv2.ListenerRule_RuleCondition, lambdaFn *sparta.LambdaAWSInfo) *ApplicationLoadBalancerDecorator
AddMultiConditionalEntry adds a new lambda target that is conditionally routed to depending on the multi condition value.
func (*ApplicationLoadBalancerDecorator) AddMultiConditionalEntryWithPriority ¶
func (albd *ApplicationLoadBalancerDecorator) AddMultiConditionalEntryWithPriority(conditions []gofelbv2.ListenerRule_RuleCondition, priority int, lambdaFn *sparta.LambdaAWSInfo) *ApplicationLoadBalancerDecorator
AddMultiConditionalEntryWithPriority adds a new lambda target that is conditionally routed to depending on the multi condition value with the given priority index
func (*ApplicationLoadBalancerDecorator) DecorateService ¶
func (albd *ApplicationLoadBalancerDecorator) DecorateService(context map[string]interface{}, serviceName string, template *gof.Template, S3Bucket string, S3Key string, buildID string, awsConfig awsv2.Config, noop bool, logger *zerolog.Logger) error
DecorateService satisfies the ServiceDecoratorHookHandler interface
func (*ApplicationLoadBalancerDecorator) LogicalResourceName ¶
func (albd *ApplicationLoadBalancerDecorator) LogicalResourceName() string
LogicalResourceName returns the CloudFormation resource name of the primary ALB
type CloudMapServiceDecorator ¶
type CloudMapServiceDecorator struct { Description string // contains filtered or unexported fields }
CloudMapServiceDecorator is an instance of a service decorator that publishes CloudMap info
func NewCloudMapServiceDecorator ¶
func NewCloudMapServiceDecorator(namespaceID string, serviceName string) (*CloudMapServiceDecorator, error)
NewCloudMapServiceDecorator returns an instance of CloudMapServiceDecorator which can be used to publish information into CloudMap
func (*CloudMapServiceDecorator) DecorateService ¶
func (cmsd *CloudMapServiceDecorator) DecorateService(context map[string]interface{}, serviceName string, template *gof.Template, S3Bucket string, S3Key string, buildID string, awsConfig awsv2.Config, noop bool, logger *zerolog.Logger) error
DecorateService satisfies the ServiceDecoratorHookHandler interface
func (*CloudMapServiceDecorator) EnableDiscoverySupport ¶
func (cmsd *CloudMapServiceDecorator) EnableDiscoverySupport(lambdaInfo *sparta.LambdaAWSInfo, additionalServiceIDs ...string) error
EnableDiscoverySupport enables the IAM privs for the CloudMap ServiceID created by this stack as well as any additional serviceIDs
func (*CloudMapServiceDecorator) LogicalResourceName ¶
func (cmsd *CloudMapServiceDecorator) LogicalResourceName() string
LogicalResourceName returns the CloudFormation Logical resource name that can be used to get information about the generated CloudFormation resource
func (*CloudMapServiceDecorator) PublishLambda ¶
func (cmsd *CloudMapServiceDecorator) PublishLambda(lookupName string, lambdaInfo *sparta.LambdaAWSInfo, additionalAttributes map[string]interface{}, logger *zerolog.Logger) error
PublishLambda publishes the known outputs for the given sparta AWS Lambda function
func (*CloudMapServiceDecorator) PublishResource ¶
func (cmsd *CloudMapServiceDecorator) PublishResource(lookupName string, resourceName string, resource gof.Resource, addditionalProperties map[string]interface{}, logger *zerolog.Logger) error
PublishResource publishes the known outputs and attributes for the given Resource instance
type DashboardTemplateData ¶
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 ¶
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 ¶
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 ¶
func NewLogAggregatorDecorator( kinesisResource *gofkinesis.Stream, kinesisMapping *sparta.EventSourceMapping, relay *sparta.LambdaAWSInfo) *LogAggregatorDecorator
NewLogAggregatorDecorator returns a ServiceDecoratorHook that registers a Kinesis stream lambda log aggregator
func (*LogAggregatorDecorator) DecorateService ¶
func (lad *LogAggregatorDecorator) DecorateService(ctx context.Context, serviceName string, template *gof.Template, lambdaFunctionCode *goflambda.Function_Code, buildID string, awsConfig awsv2.Config, noop bool, logger *zerolog.Logger) (context.Context, error)
DecorateService annotates the service with the Kinesis hook
func (*LogAggregatorDecorator) DecorateTemplate ¶
func (lad *LogAggregatorDecorator) DecorateTemplate(ctx context.Context, serviceName string, lambdaResourceName string, lambdaResource *goflambda.Function, resourceMetadata map[string]interface{}, lambdaFunctionCode *goflambda.Function_Code, buildID string, template *gof.Template, logger *zerolog.Logger) (context.Context, error)
DecorateTemplate annotates the lambda with the log forwarding sink info
func (*LogAggregatorDecorator) KinesisLogicalResourceName ¶
func (lad *LogAggregatorDecorator) KinesisLogicalResourceName() string
KinesisLogicalResourceName returns the name of the Kinesis stream that will be provisioned by this Decorator