@@ -117,7 +117,7 @@ export interface StateMachineProps {
117117 *
118118 * @default A role is automatically created
119119 */
120- readonly role ?: iam . IRoleRef & iam . IGrantable ;
120+ readonly role ?: iam . IRole ;
121121
122122 /**
123123 * Maximum run time for this state machine
@@ -427,6 +427,11 @@ export class StateMachine extends StateMachineBase {
427427 */
428428 public static readonly PROPERTY_INJECTION_ID : string = 'aws-cdk-lib.aws-stepfunctions.StateMachine' ;
429429
430+ /**
431+ * Execution role of this state machine
432+ */
433+ public readonly role : iam . IRole ;
434+
430435 /**
431436 * The name of the state machine
432437 * @attribute
@@ -450,11 +455,6 @@ export class StateMachine extends StateMachineBase {
450455 */
451456 public readonly stateMachineRevisionId : string ;
452457
453- /**
454- * Execution role of this state machine
455- */
456- private readonly _role : iam . IRoleRef & iam . IGrantable ;
457-
458458 constructor ( scope : Construct , id : string , props : StateMachineProps ) {
459459 super ( scope , id , {
460460 physicalName : props . stateMachineName ,
@@ -476,7 +476,7 @@ export class StateMachine extends StateMachineBase {
476476 this . validateLogOptions ( props . logs ) ;
477477 }
478478
479- this . _role = props . role || new iam . Role ( this , 'Role' , {
479+ this . role = props . role || new iam . Role ( this , 'Role' , {
480480 assumedBy : new iam . ServicePrincipal ( 'states.amazonaws.com' ) ,
481481 } ) ;
482482
@@ -494,7 +494,7 @@ export class StateMachine extends StateMachineBase {
494494 }
495495
496496 if ( props . encryptionConfiguration instanceof CustomerManagedEncryptionConfiguration ) {
497- this . _role . grantPrincipal . addToPrincipalPolicy ( new iam . PolicyStatement ( {
497+ this . role . addToPrincipalPolicy ( new iam . PolicyStatement ( {
498498 effect : iam . Effect . ALLOW ,
499499 actions : [
500500 'kms:Decrypt' , 'kms:GenerateDataKey' ,
@@ -513,7 +513,7 @@ export class StateMachine extends StateMachineBase {
513513 } ) ) ;
514514
515515 if ( props . logs && props . logs . level !== LogLevel . OFF ) {
516- this . _role . grantPrincipal . addToPrincipalPolicy ( new iam . PolicyStatement ( {
516+ this . role . addToPrincipalPolicy ( new iam . PolicyStatement ( {
517517 effect : iam . Effect . ALLOW ,
518518 actions : [
519519 'kms:GenerateDataKey' ,
@@ -540,10 +540,10 @@ export class StateMachine extends StateMachineBase {
540540 const resource = new CfnStateMachine ( this , 'Resource' , {
541541 stateMachineName : this . physicalName ,
542542 stateMachineType : props . stateMachineType ?? undefined ,
543- roleArn : this . _role . roleRef . roleArn ,
543+ roleArn : this . role . roleArn ,
544544 loggingConfiguration : props . logs ? this . buildLoggingConfiguration ( props . logs ) : undefined ,
545545 tracingConfiguration : this . buildTracingConfiguration ( props . tracingEnabled ) ,
546- ...definitionBody . bind ( this , this . _role . grantPrincipal , props , graph ) ,
546+ ...definitionBody . bind ( this , this . role , props , graph ) ,
547547 definitionSubstitutions : props . definitionSubstitutions ,
548548 encryptionConfiguration : buildEncryptionConfiguration ( props . encryptionConfiguration ) ,
549549 } ) ;
@@ -569,27 +569,15 @@ export class StateMachine extends StateMachineBase {
569569 * The principal this state machine is running as
570570 */
571571 public get grantPrincipal ( ) {
572- return this . _role . grantPrincipal ;
573- }
574-
575- /**
576- * Execution role of this state machine
577- *
578- * Will throw if the Role object that was given does not implement IRole
579- */
580- public get role ( ) : iam . IRole {
581- if ( ! isIRole ( this . _role ) ) {
582- throw new ValidationError ( `The role given to this StateMachine is not an IRole, but ${ this . _role . constructor . name } ` , this ) ;
583- }
584- return this . _role ;
572+ return this . role . grantPrincipal ;
585573 }
586574
587575 /**
588576 * Add the given statement to the role's policy
589577 */
590578 @MethodMetadata ( )
591579 public addToRolePolicy ( statement : iam . PolicyStatement ) {
592- this . _role . grantPrincipal . addToPrincipalPolicy ( statement ) ;
580+ this . role . addToPrincipalPolicy ( statement ) ;
593581 }
594582
595583 private validateStateMachineName ( stateMachineName : string ) {
@@ -858,9 +846,3 @@ export class ChainDefinitionBody extends DefinitionBody {
858846 } ;
859847 }
860848}
861-
862- function isIRole ( x : iam . IRoleRef ) : x is iam . IRole {
863- const xx = x as iam . IRole ;
864- return ( ! ! xx . addManagedPolicy && ! ! xx . addToPrincipalPolicy && ! ! xx . assumeRoleAction && ! ! xx . attachInlinePolicy
865- && ! ! xx . grant && ! ! xx . policyFragment ) ;
866- }
0 commit comments