Class ServicePrincipal

All Implemented Interfaces:
IAssumeRolePrincipal, IComparablePrincipal, IGrantable, IPrincipal,

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-24T02:42:39.158Z") @Stability(Stable) public class ServicePrincipal extends PrincipalBase
An IAM principal that represents an AWS service (i.e.


 Role lambdaRole = Role.Builder.create(this, "Role")
         .assumedBy(new ServicePrincipal(""))
         .description("Example role...")
 Stream stream = Stream.Builder.create(this, "MyEncryptedStream")
 // give lambda permissions to read stream
  • Constructor Details

    • ServicePrincipal

      protected ServicePrincipal( objRef)
    • ServicePrincipal

      protected ServicePrincipal( initializationMode)
    • ServicePrincipal

      @Stability(Stable) public ServicePrincipal(@NotNull String service, @Nullable ServicePrincipalOpts opts)
      Reference an AWS service, optionally in a given region.

      service - AWS service (i.e. This parameter is required.
      opts -
    • ServicePrincipal

      @Stability(Stable) public ServicePrincipal(@NotNull String service)
      Reference an AWS service, optionally in a given region.

      service - AWS service (i.e. This parameter is required.
  • Method Details

    • servicePrincipalName

      @Stability(Stable) @NotNull public static String servicePrincipalName(@NotNull String service)
      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>

      If the feature flag @aws-cdk/aws-iam:standardizedServicePrincipals is set, this method will always return its input. If this feature flag is not set, this method will perform the legacy behavior, which appends the region-specific domain suffix for some select services (for example, it would append .cn to some service principal names).


       String principalName = ServicePrincipal.servicePrincipalName("");

      service - This parameter is required.
    • dedupeString

      @Stability(Stable) @Nullable public String dedupeString()
      Return whether or not this principal is equal to the given principal.
      Specified by:
      dedupeString in interface IComparablePrincipal
      Specified by:
      dedupeString in class PrincipalBase
    • toString

      @Stability(Stable) @NotNull public String toString()
      Returns a string representation of an object.
      toString in class PrincipalBase
    • getPolicyFragment

      @Stability(Stable) @NotNull public PrincipalPolicyFragment getPolicyFragment()
      Return the policy fragment that identifies this principal in a Policy.
      Specified by:
      getPolicyFragment in interface IPrincipal
      Specified by:
      getPolicyFragment in class PrincipalBase
    • getService

      @Stability(Stable) @NotNull public String getService()
      AWS service (i.e.