Class ServicePrincipal
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.iam.PrincipalBase
software.amazon.awscdk.services.iam.ServicePrincipal
- All Implemented Interfaces:
IAssumeRolePrincipal
,IComparablePrincipal
,IGrantable
,IPrincipal
,software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.104.0 (build e79254c)",
date="2025-01-15T21:09:20.347Z")
@Stability(Stable)
public class ServicePrincipal
extends PrincipalBase
An IAM principal that represents an AWS service (i.e.
sqs.amazonaws.com
).
Example:
IChainable definition; Role role = Role.Builder.create(this, "Role") .assumedBy(new ServicePrincipal("lambda.amazonaws.com")) .build(); StateMachine stateMachine = StateMachine.Builder.create(this, "StateMachine") .definitionBody(DefinitionBody.fromChainable(definition)) .build(); // Give role permission to get execution history of ALL executions for the state machine stateMachine.grantExecution(role, "states:GetExecutionHistory");
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.iam.IAssumeRolePrincipal
IAssumeRolePrincipal.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.iam.IComparablePrincipal
IComparablePrincipal.Jsii$Default
-
Constructor Summary
ModifierConstructorDescriptionServicePrincipal
(String service) Reference an AWS service, optionally in a given region.ServicePrincipal
(String service, ServicePrincipalOpts opts) Reference an AWS service, optionally in a given region.protected
ServicePrincipal
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
ServicePrincipal
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionReturn whether or not this principal is equal to the given principal.static ServicePrincipal
fromStaticServicePrincipleName
(String servicePrincipalName) Return the service principal using the service principal name as it is passed to the function without any change regardless of the region used in the stack if it is Opted in or not.Return the policy fragment that identifies this principal in a Policy.AWS service (i.e.static String
servicePrincipalName
(String service) Return the service principal name based on the region it's used in.toString()
Returns a string representation of an object.Methods inherited from class software.amazon.awscdk.services.iam.PrincipalBase
addToAssumeRolePolicy, addToPolicy, addToPrincipalPolicy, getAssumeRoleAction, getGrantPrincipal, getPrincipalAccount, toJSON, withConditions, withSessionTags
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
ServicePrincipal
protected ServicePrincipal(software.amazon.jsii.JsiiObjectRef objRef) -
ServicePrincipal
protected ServicePrincipal(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
ServicePrincipal
@Stability(Stable) public ServicePrincipal(@NotNull String service, @Nullable ServicePrincipalOpts opts) Reference an AWS service, optionally in a given region.- Parameters:
service
- AWS service (i.e. sqs.amazonaws.com). This parameter is required.opts
-
-
ServicePrincipal
Reference an AWS service, optionally in a given region.- Parameters:
service
- AWS service (i.e. sqs.amazonaws.com). This parameter is required.
-
-
Method Details
-
fromStaticServicePrincipleName
@Stability(Stable) @NotNull public static ServicePrincipal fromStaticServicePrincipleName(@NotNull String servicePrincipalName) Return the service principal using the service principal name as it is passed to the function without any change regardless of the region used in the stack if it is Opted in or not.Example:
ServicePrincipal principalName = ServicePrincipal.fromStaticServicePrincipleName("elasticmapreduce.amazonaws.com.cn");
- Parameters:
servicePrincipalName
- This parameter is required.
-
servicePrincipalName
Return the service principal name based on the region it's used in.Some service principal names used to be different for different partitions, and some were not. This method would return the appropriate region-specific service principal name, getting that information from the
region-info
module.These days all service principal names are standardized, and they are all of the form
<servicename>.amazonaws.com
.To avoid breaking changes, handling is provided for services added with the formats below, however, no additional handling will be added for new regions or partitions.
- s3
- s3.amazonaws.com
- s3.amazonaws.com.cn
- s3.c2s.ic.gov
- s3.sc2s.sgov.gov
Example:
String principalName = ServicePrincipal.servicePrincipalName("ec2.amazonaws.com");
- Parameters:
service
- This parameter is required.
-
dedupeString
Return whether or not this principal is equal to the given principal.- Specified by:
dedupeString
in interfaceIComparablePrincipal
- Specified by:
dedupeString
in classPrincipalBase
-
toString
Returns a string representation of an object.- Overrides:
toString
in classPrincipalBase
-
getPolicyFragment
Return the policy fragment that identifies this principal in a Policy.- Specified by:
getPolicyFragment
in interfaceIPrincipal
- Specified by:
getPolicyFragment
in classPrincipalBase
-
getService
AWS service (i.e. sqs.amazonaws.com).
-