1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package eventbridge 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/eventbridge/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12) 13 14// Creates or updates the specified rule. Rules are enabled by default, or based on 15// value of the state. You can disable a rule using DisableRule. A single rule 16// watches for events from a single event bus. Events generated by AWS services go 17// to your account's default event bus. Events generated by SaaS partner services 18// or applications go to the matching partner event bus. If you have custom 19// applications or services, you can specify whether their events go to your 20// default event bus or a custom event bus that you have created. For more 21// information, see CreateEventBus. If you are updating an existing rule, the rule 22// is replaced with what you specify in this PutRule command. If you omit arguments 23// in PutRule, the old values for those arguments are not kept. Instead, they are 24// replaced with null values. When you create or update a rule, incoming events 25// might not immediately start matching to new or updated rules. Allow a short 26// period of time for changes to take effect. A rule must contain at least an 27// EventPattern or ScheduleExpression. Rules with EventPatterns are triggered when 28// a matching event is observed. Rules with ScheduleExpressions self-trigger based 29// on the given schedule. A rule can have both an EventPattern and a 30// ScheduleExpression, in which case the rule triggers on matching events as well 31// as on a schedule. When you initially create a rule, you can optionally assign 32// one or more tags to the rule. Tags can help you organize and categorize your 33// resources. You can also use them to scope user permissions, by granting a user 34// permission to access or change only rules with certain tag values. To use the 35// PutRule operation and assign tags, you must have both the events:PutRule and 36// events:TagResource permissions. If you are updating an existing rule, any tags 37// you specify in the PutRule operation are ignored. To update the tags of an 38// existing rule, use TagResource and UntagResource. Most services in AWS treat : 39// or / as the same character in Amazon Resource Names (ARNs). However, EventBridge 40// uses an exact match in event patterns and rules. Be sure to use the correct ARN 41// characters when creating event patterns so that they match the ARN syntax in the 42// event you want to match. In EventBridge, it is possible to create rules that 43// lead to infinite loops, where a rule is fired repeatedly. For example, a rule 44// might detect that ACLs have changed on an S3 bucket, and trigger software to 45// change them to the desired state. If the rule is not written carefully, the 46// subsequent change to the ACLs fires the rule again, creating an infinite loop. 47// To prevent this, write the rules so that the triggered actions do not re-fire 48// the same rule. For example, your rule could fire only if ACLs are found to be in 49// a bad state, instead of after any change. An infinite loop can quickly cause 50// higher than expected charges. We recommend that you use budgeting, which alerts 51// you when charges exceed your specified limit. For more information, see Managing 52// Your Costs with Budgets 53// (https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/budgets-managing-costs.html). 54func (c *Client) PutRule(ctx context.Context, params *PutRuleInput, optFns ...func(*Options)) (*PutRuleOutput, error) { 55 if params == nil { 56 params = &PutRuleInput{} 57 } 58 59 result, metadata, err := c.invokeOperation(ctx, "PutRule", params, optFns, addOperationPutRuleMiddlewares) 60 if err != nil { 61 return nil, err 62 } 63 64 out := result.(*PutRuleOutput) 65 out.ResultMetadata = metadata 66 return out, nil 67} 68 69type PutRuleInput struct { 70 71 // The name of the rule that you are creating or updating. 72 // 73 // This member is required. 74 Name *string 75 76 // A description of the rule. 77 Description *string 78 79 // The name or ARN of the event bus to associate with this rule. If you omit this, 80 // the default event bus is used. 81 EventBusName *string 82 83 // The event pattern. For more information, see Events and Event Patterns 84 // (https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html) 85 // in the Amazon EventBridge User Guide. 86 EventPattern *string 87 88 // The Amazon Resource Name (ARN) of the IAM role associated with the rule. 89 RoleArn *string 90 91 // The scheduling expression. For example, "cron(0 20 * * ? *)" or "rate(5 92 // minutes)". 93 ScheduleExpression *string 94 95 // Indicates whether the rule is enabled or disabled. 96 State types.RuleState 97 98 // The list of key-value pairs to associate with the rule. 99 Tags []types.Tag 100} 101 102type PutRuleOutput struct { 103 104 // The Amazon Resource Name (ARN) of the rule. 105 RuleArn *string 106 107 // Metadata pertaining to the operation's result. 108 ResultMetadata middleware.Metadata 109} 110 111func addOperationPutRuleMiddlewares(stack *middleware.Stack, options Options) (err error) { 112 err = stack.Serialize.Add(&awsAwsjson11_serializeOpPutRule{}, middleware.After) 113 if err != nil { 114 return err 115 } 116 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpPutRule{}, middleware.After) 117 if err != nil { 118 return err 119 } 120 if err = addSetLoggerMiddleware(stack, options); err != nil { 121 return err 122 } 123 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 124 return err 125 } 126 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addResolveEndpointMiddleware(stack, options); err != nil { 130 return err 131 } 132 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 133 return err 134 } 135 if err = addRetryMiddlewares(stack, options); err != nil { 136 return err 137 } 138 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 139 return err 140 } 141 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 142 return err 143 } 144 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 145 return err 146 } 147 if err = addClientUserAgent(stack); err != nil { 148 return err 149 } 150 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 151 return err 152 } 153 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 154 return err 155 } 156 if err = addOpPutRuleValidationMiddleware(stack); err != nil { 157 return err 158 } 159 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutRule(options.Region), middleware.Before); err != nil { 160 return err 161 } 162 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 163 return err 164 } 165 if err = addResponseErrorMiddleware(stack); err != nil { 166 return err 167 } 168 if err = addRequestResponseLogging(stack, options); err != nil { 169 return err 170 } 171 return nil 172} 173 174func newServiceMetadataMiddleware_opPutRule(region string) *awsmiddleware.RegisterServiceMetadata { 175 return &awsmiddleware.RegisterServiceMetadata{ 176 Region: region, 177 ServiceID: ServiceID, 178 SigningName: "events", 179 OperationName: "PutRule", 180 } 181} 182