You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(events-targets): add documentation of invoking AwsApi method (#35309)
### Issue # (if applicable)
None
### Reason for this change
The `targets.AwsApi()` method enables us to call AWS API from EventBridge directly but there is no documentation about this feature.
### Description of changes
Update README.md
### Describe any new or updated permissions being added
None
### Description of how you validated changes
None
### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Use the `AwsApi` target to make direct AWS API calls from EventBridge rules. This is useful for invoking AWS services that don't have a dedicated EventBridge target.
340
+
341
+
### Basic Usage
342
+
343
+
The following example shows how to update an ECS service when a rule is triggered:
By default, the AwsApi target automatically creates the necessary IAM permissions based on the service and action you specify. The permission format follows the pattern: `service:Action`.
363
+
364
+
For example:
365
+
366
+
-`ECS` service with `updateService` action → `ecs:UpdateService` permission
367
+
-`RDS` service with `createDBSnapshot` action → `rds:CreateDBSnapshot` permission
368
+
369
+
### Custom IAM Policy
370
+
371
+
In some cases, you may need to provide a custom IAM policy statement, especially when:
372
+
373
+
- You need to restrict permissions to specific resources (instead of `*`)
374
+
- The service requires additional permissions beyond the main action
375
+
- You want more granular control over the permissions
376
+
377
+
```ts
378
+
import*asiamfrom'aws-cdk-lib/aws-iam';
379
+
import*ass3from'aws-cdk-lib/aws-s3';
380
+
381
+
declareconst rule:events.Rule;
382
+
declareconst bucket:s3.Bucket;
383
+
384
+
rule.addTarget(newtargets.AwsApi({
385
+
service: 's3',
386
+
action: 'GetBucketEncryption',
387
+
parameters: {
388
+
Bucket: bucket.bucketName,
389
+
},
390
+
policyStatement: newiam.PolicyStatement({
391
+
effect: iam.Effect.ALLOW,
392
+
actions: ['s3:GetEncryptionConfiguration'],
393
+
resources: [bucket.bucketArn],
394
+
}),
395
+
}));
396
+
```
397
+
336
398
## Invoke an API Destination
337
399
338
400
Use the `targets.ApiDestination` target to trigger an external API. You need to
0 commit comments