gpt4 book ai didi

amazon-web-services - 使用 CDK/CloudFormation 进行 Cognito 属性映射

转载 作者:行者123 更新时间:2023-12-03 07:19:50 25 4
gpt4 key购买 nike

根据描述here在其他页面上,我通过 CDK 创建了 Cognito 用户池和身份池,并且在手动映射自定义属性后,根据用户池中的自定义属性授予访问权限。

现在我正在尝试在 CDK 中完成所有操作,但我不知道如何进行自定义属性的映射。我发现唯一知道的关于属性映射是 UserPoolIdentityProvider/CfnUserPoolIdentityProvider ,但这是错误的类型,我不能将它与一个CfnIdentityPoolcognitoIdentityProviders中。

我看到了一些关于同一问题的未答复帖子( this ,或this ), 但希望最后会消逝,所以我想这次也许会有答案。

我的印象是一切都可以通过 CloudFormation 完成,但这似乎是错误的,因为 this post和别的建议。

那么属性映射可以使用 CDK 完成吗?或者如果我想自动化此操作,我需要使用自定义资源和 Lambda(或者其他东西)?

最佳答案

感谢原创者。发现这很有用并解决了自定义资源的问题。

https://github.com/aws-samples/amazon-cognito-abac-authorization-with-react-example/blob/main/lib/cognito_identity_pool_sample-stack.ts

 new cognito.CfnIdentityPoolRoleAttachment(this, "defaultRoles", {
identityPoolId: identityPool.ref,
roles: {
'authenticated': authRole.attrArn
}
})

const createParameters = {
"IdentityPoolId": identityPool.ref,
"IdentityProviderName": userPool.userPoolProviderName,
"PrincipalTags": {
"department": "department"
},
"UseDefaults": false
}

const setPrincipalTagAction = {
action: "setPrincipalTagAttributeMap",
service: "CognitoIdentity",
parameters: createParameters,
physicalResourceId: customResources.PhysicalResourceId.of(identityPool.ref)
}

const { region, account } = Stack.of(this)
const identityPoolArn = `arn:aws:cognito-identity:${region}:${account}:identitypool/${identityPool.ref}`

// Creates a Custom resource (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.custom_resources-readme.html)
// This is necessary to attach Principal Tag mappings to the Identity Pool after it has been created.
// This uses the SDK, rather than CDK code, as attaching Principal Tags through CDK is currently not supported yet
new customResources.AwsCustomResource(this, 'CustomResourcePrincipalTags', {
onCreate: setPrincipalTagAction,
onUpdate: setPrincipalTagAction,
policy: customResources.AwsCustomResourcePolicy.fromSdkCalls({
resources: [identityPoolArn],
}),
})

关于amazon-web-services - 使用 CDK/CloudFormation 进行 Cognito 属性映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70777999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com