Skip to content

Commit e220bc8

Browse files
authoredFeb 27, 2025
fix(cognito-identitypool-alpha): prevent stacks from not deploying correctly (#33609)
### Issue # (if applicable) Closes #33510 ### Reason for this change A previous change ([PR33305](#33305)) removed the `IdentityPoolRoleAttachment` L2 construct, which also changed the creation logic of the default role attachment in the `IdentityPool` L2. This not only triggered redeployments, but did not allow for redeployment at all, as the new role attachment (with a different resource hash) was trying to be created before the old one was removed. This led to failed deployments, as only one role attachment can exist per identity pool. ### Description of changes Brought back the `IdentityPoolRoleAttachment` L2 logic to prevent redeployment for customers using CDK `<v2.179.0`. However, the construct is now no longer being exported, which preserves the original intention of preventing confusion about using this resource. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes `yarn test && yarn integ test/integ.identitypool.js --update-on-failed` ### 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) **BREAKING CHANGE**: Any `IdentityPool` resources deployed in versions `>=2.179.0` will now fail to deploy. You will need to delete the `IdentityPoolRoleAttachment` from your stack via the console before redeploying. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent dd0d62f commit e220bc8

7 files changed

+192
-107
lines changed
 

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/lib/identitypool.ts

+79-13
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export class IdentityPool extends Resource implements IIdentityPool {
440440
/**
441441
* Role Provider for the default Role for authenticated users
442442
*/
443-
private readonly roleAttachment: CfnIdentityPoolRoleAttachment;
443+
private readonly roleAttachment: IdentityPoolRoleAttachment;
444444

445445
/**
446446
* List of Identity Providers added in constructor for use with property overrides
@@ -495,18 +495,11 @@ export class IdentityPool extends Resource implements IIdentityPool {
495495
this.unauthenticatedRole = props.unauthenticatedRole ? props.unauthenticatedRole : this.configureDefaultRole('Unauthenticated');
496496

497497
// Set up Role Attachment
498-
const mappings = props.roleMappings || [];
499-
let roleMappings: any = undefined;
500-
if (mappings) {
501-
roleMappings = this.configureRoleMappings(...mappings);
502-
}
503-
this.roleAttachment = new CfnIdentityPoolRoleAttachment(this, 'DefaultRoleAttachment', {
504-
identityPoolId: this.identityPoolId,
505-
roles: {
506-
authenticated: this.authenticatedRole.roleArn,
507-
unauthenticated: this.unauthenticatedRole.roleArn,
508-
},
509-
roleMappings,
498+
this.roleAttachment = new IdentityPoolRoleAttachment(this, 'DefaultRoleAttachment', {
499+
identityPool: this,
500+
authenticatedRole: this.authenticatedRole,
501+
unauthenticatedRole: this.unauthenticatedRole,
502+
roleMappings: props.roleMappings,
510503
});
511504

512505
Array.isArray(this.roleAttachment);
@@ -544,6 +537,79 @@ export class IdentityPool extends Resource implements IIdentityPool {
544537
},
545538
}, 'sts:AssumeRoleWithWebIdentity');
546539
}
540+
}
541+
542+
/**
543+
* Represents an Identity Pool Role Attachment
544+
*/
545+
interface IIdentityPoolRoleAttachment extends IResource {
546+
/**
547+
* ID of the Attachment's underlying Identity Pool
548+
*/
549+
readonly identityPoolId: string;
550+
}
551+
552+
/**
553+
* Props for an Identity Pool Role Attachment
554+
*/
555+
interface IdentityPoolRoleAttachmentProps {
556+
557+
/**
558+
* ID of the Attachment's underlying Identity Pool
559+
*/
560+
readonly identityPool: IIdentityPool;
561+
562+
/**
563+
* Default authenticated (User) Role
564+
* @default - No default authenticated Role will be added
565+
*/
566+
readonly authenticatedRole?: IRole;
567+
568+
/**
569+
* Default unauthenticated (Guest) Role
570+
* @default - No default unauthenticated Role will be added
571+
*/
572+
readonly unauthenticatedRole?: IRole;
573+
574+
/**
575+
* Rules for mapping roles to users
576+
* @default - No role mappings
577+
*/
578+
readonly roleMappings?: IdentityPoolRoleMapping[];
579+
}
580+
581+
/**
582+
* Defines an Identity Pool Role Attachment
583+
*
584+
* @resource AWS::Cognito::IdentityPoolRoleAttachment
585+
*/
586+
class IdentityPoolRoleAttachment extends Resource implements IIdentityPoolRoleAttachment {
587+
/**
588+
* ID of the underlying Identity Pool
589+
*/
590+
public readonly identityPoolId: string;
591+
592+
constructor(scope: Construct, id: string, props: IdentityPoolRoleAttachmentProps) {
593+
super(scope, id);
594+
// Enhanced CDK Analytics Telemetry
595+
addConstructMetadata(this, props);
596+
this.identityPoolId = props.identityPool.identityPoolId;
597+
const mappings = props.roleMappings || [];
598+
let roles: any = undefined, roleMappings: any = undefined;
599+
if (props.authenticatedRole || props.unauthenticatedRole) {
600+
roles = {};
601+
if (props.authenticatedRole) roles.authenticated = props.authenticatedRole.roleArn;
602+
if (props.unauthenticatedRole) roles.unauthenticated = props.unauthenticatedRole.roleArn;
603+
}
604+
if (mappings) {
605+
roleMappings = this.configureRoleMappings(...mappings);
606+
}
607+
new CfnIdentityPoolRoleAttachment(this, 'Resource', {
608+
identityPoolId: this.identityPoolId,
609+
roles,
610+
roleMappings,
611+
});
612+
}
547613

548614
/**
549615
* Configures role mappings for the Identity Pool Role Attachment

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/test/integ.identitypool.js.snapshot/integ-idp.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/test/integ.identitypool.js.snapshot/integ-idp.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@
485485
"PooltestClientFE8D4935"
486486
]
487487
},
488-
"identitypoolDefaultRoleAttachment9339A8E5": {
488+
"identitypoolDefaultRoleAttachment6BCAB114": {
489489
"Type": "AWS::Cognito::IdentityPoolRoleAttachment",
490490
"Properties": {
491491
"IdentityPoolId": {

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/test/integ.identitypool.js.snapshot/integidentitypoolDefaultTestDeployAssert8F0BD226.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/test/integ.identitypool.js.snapshot/integidentitypoolDefaultTestDeployAssert8F0BD226.template.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk/aws-cognito-identitypool-alpha/test/integ.identitypool.js.snapshot/manifest.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Failed to load comments.