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// Adds the specified targets to the specified rule, or updates the targets if they
15// are already associated with the rule. Targets are the resources that are invoked
16// when a rule is triggered. You can configure the following as targets for
17// Events:
18//
19// * API destination
20// (https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-api-destinations.html)
21//
22// *
23// Amazon API Gateway REST API endpoints
24//
25// * API Gateway
26//
27// * Batch job queue
28//
29// *
30// CloudWatch Logs group
31//
32// * CodeBuild project
33//
34// * CodePipeline
35//
36// * Amazon EC2
37// CreateSnapshot API call
38//
39// * Amazon EC2 RebootInstances API call
40//
41// * Amazon EC2
42// StopInstances API call
43//
44// * Amazon EC2 TerminateInstances API call
45//
46// * Amazon ECS
47// tasks
48//
49// * Event bus in a different Amazon Web Services account or Region. You can
50// use an event bus in the US East (N. Virginia) us-east-1, US West (Oregon)
51// us-west-2, or Europe (Ireland) eu-west-1 Regions as a target for a rule.
52//
53// *
54// Firehose delivery stream (Kinesis Data Firehose)
55//
56// * Inspector assessment
57// template (Amazon Inspector)
58//
59// * Kinesis stream (Kinesis Data Stream)
60//
61// * Lambda
62// function
63//
64// * Redshift clusters (Data API statement execution)
65//
66// * Amazon SNS
67// topic
68//
69// * Amazon SQS queues (includes FIFO queues
70//
71// * SSM Automation
72//
73// * SSM
74// OpsItem
75//
76// * SSM Run Command
77//
78// * Step Functions state machines
79//
80// Creating rules with
81// built-in targets is supported only in the Amazon Web Services Management
82// Console. The built-in targets are EC2 CreateSnapshot API call, EC2
83// RebootInstances API call, EC2 StopInstances API call, and EC2 TerminateInstances
84// API call. For some target types, PutTargets provides target-specific parameters.
85// If the target is a Kinesis data stream, you can optionally specify which shard
86// the event goes to by using the KinesisParameters argument. To invoke a command
87// on multiple EC2 instances with one rule, you can use the RunCommandParameters
88// field. To be able to make API calls against the resources that you own, Amazon
89// EventBridge needs the appropriate permissions. For Lambda and Amazon SNS
90// resources, EventBridge relies on resource-based policies. For EC2 instances,
91// Kinesis Data Streams, Step Functions state machines and API Gateway REST APIs,
92// EventBridge relies on IAM roles that you specify in the RoleARN argument in
93// PutTargets. For more information, see Authentication and Access Control
94// (https://docs.aws.amazon.com/eventbridge/latest/userguide/auth-and-access-control-eventbridge.html)
95// in the Amazon EventBridge User Guide. If another Amazon Web Services account is
96// in the same region and has granted you permission (using PutPermission), you can
97// send events to that account. Set that account's event bus as a target of the
98// rules in your account. To send the matched events to the other account, specify
99// that account's event bus as the Arn value when you run PutTargets. If your
100// account sends events to another account, your account is charged for each sent
101// event. Each event sent to another account is charged as a custom event. The
102// account receiving the event is not charged. For more information, see Amazon
103// EventBridge Pricing (http://aws.amazon.com/eventbridge/pricing/). Input,
104// InputPath, and InputTransformer are not available with PutTarget if the target
105// is an event bus of a different Amazon Web Services account. If you are setting
106// the event bus of another account as the target, and that account granted
107// permission to your account through an organization instead of directly by the
108// account ID, then you must specify a RoleArn with proper permissions in the
109// Target structure. For more information, see Sending and Receiving Events Between
110// Amazon Web Services Accounts
111// (https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-cross-account-event-delivery.html)
112// in the Amazon EventBridge User Guide. For more information about enabling
113// cross-account events, see PutPermission
114// (https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutPermission.html).
115// Input, InputPath, and InputTransformer are mutually exclusive and optional
116// parameters of a target. When a rule is triggered due to a matched event:
117//
118// * If
119// none of the following arguments are specified for a target, then the entire
120// event is passed to the target in JSON format (unless the target is Amazon EC2
121// Run Command or Amazon ECS task, in which case nothing from the event is passed
122// to the target).
123//
124// * If Input is specified in the form of valid JSON, then the
125// matched event is overridden with this constant.
126//
127// * If InputPath is specified in
128// the form of JSONPath (for example, $.detail), then only the part of the event
129// specified in the path is passed to the target (for example, only the detail part
130// of the event is passed).
131//
132// * If InputTransformer is specified, then one or more
133// specified JSONPaths are extracted from the event and used as values in a
134// template that you specify as the input to the target.
135//
136// When you specify
137// InputPath or InputTransformer, you must use JSON dot notation, not bracket
138// notation. When you add targets to a rule and the associated rule triggers soon
139// after, new or updated targets might not be immediately invoked. Allow a short
140// period of time for changes to take effect. This action can partially fail if too
141// many requests are made at the same time. If that happens, FailedEntryCount is
142// non-zero in the response and each entry in FailedEntries provides the ID of the
143// failed target and the error code.
144func (c *Client) PutTargets(ctx context.Context, params *PutTargetsInput, optFns ...func(*Options)) (*PutTargetsOutput, error) {
145	if params == nil {
146		params = &PutTargetsInput{}
147	}
148
149	result, metadata, err := c.invokeOperation(ctx, "PutTargets", params, optFns, c.addOperationPutTargetsMiddlewares)
150	if err != nil {
151		return nil, err
152	}
153
154	out := result.(*PutTargetsOutput)
155	out.ResultMetadata = metadata
156	return out, nil
157}
158
159type PutTargetsInput struct {
160
161	// The name of the rule.
162	//
163	// This member is required.
164	Rule *string
165
166	// The targets to update or add to the rule.
167	//
168	// This member is required.
169	Targets []types.Target
170
171	// The name or ARN of the event bus associated with the rule. If you omit this, the
172	// default event bus is used.
173	EventBusName *string
174
175	noSmithyDocumentSerde
176}
177
178type PutTargetsOutput struct {
179
180	// The failed target entries.
181	FailedEntries []types.PutTargetsResultEntry
182
183	// The number of failed entries.
184	FailedEntryCount int32
185
186	// Metadata pertaining to the operation's result.
187	ResultMetadata middleware.Metadata
188
189	noSmithyDocumentSerde
190}
191
192func (c *Client) addOperationPutTargetsMiddlewares(stack *middleware.Stack, options Options) (err error) {
193	err = stack.Serialize.Add(&awsAwsjson11_serializeOpPutTargets{}, middleware.After)
194	if err != nil {
195		return err
196	}
197	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpPutTargets{}, middleware.After)
198	if err != nil {
199		return err
200	}
201	if err = addSetLoggerMiddleware(stack, options); err != nil {
202		return err
203	}
204	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
205		return err
206	}
207	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
208		return err
209	}
210	if err = addResolveEndpointMiddleware(stack, options); err != nil {
211		return err
212	}
213	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
214		return err
215	}
216	if err = addRetryMiddlewares(stack, options); err != nil {
217		return err
218	}
219	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
220		return err
221	}
222	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
223		return err
224	}
225	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
226		return err
227	}
228	if err = addClientUserAgent(stack); err != nil {
229		return err
230	}
231	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
232		return err
233	}
234	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
235		return err
236	}
237	if err = addOpPutTargetsValidationMiddleware(stack); err != nil {
238		return err
239	}
240	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPutTargets(options.Region), middleware.Before); err != nil {
241		return err
242	}
243	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
244		return err
245	}
246	if err = addResponseErrorMiddleware(stack); err != nil {
247		return err
248	}
249	if err = addRequestResponseLogging(stack, options); err != nil {
250		return err
251	}
252	return nil
253}
254
255func newServiceMetadataMiddleware_opPutTargets(region string) *awsmiddleware.RegisterServiceMetadata {
256	return &awsmiddleware.RegisterServiceMetadata{
257		Region:        region,
258		ServiceID:     ServiceID,
259		SigningName:   "events",
260		OperationName: "PutTargets",
261	}
262}
263