[AWS CDK] Cognito を構築
2022-03-046 min read
目次
概要
AWS CDK v2 で Cognito を構築した際のCDK Stackです。
Stack
以下のソースが AWS CDK のスタックです。
import {
App,
Stack,
StackProps,
RemovalPolicy,
aws_cognito as cognito,
} from "aws-cdk-lib";
export class CognitoAuthStack extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
const project: string = "myproject";
const stage: string = "dev";
const userPool = new cognito.UserPool(this, `${project}-user-pool`, {
userPoolName: `${project}-user-pool`,
selfSignUpEnabled: true, // サインアップ有効
standardAttributes: {
email: { required: true, mutable: true },
},
signInAliases: { email: true },
accountRecovery: cognito.AccountRecovery.EMAIL_ONLY,
removalPolicy: RemovalPolicy.DESTROY,
});
const domainPrefix = `${project}`;
new cognito.UserPoolDomain(this, "UserPoolDomain", {
userPool: userPool,
cognitoDomain: {
domainPrefix: domainPrefix,
},
});
userPool.addClient("client", {
userPoolClientName: `${project}-${stage}-client`,
oAuth: {
scopes: [
cognito.OAuthScope.EMAIL,
cognito.OAuthScope.OPENID,
cognito.OAuthScope.PROFILE,
],
callbackUrls: ["http://example.com:8080/callback"],
logoutUrls: ["http://example.com:8080/logout"],
flows: {
authorizationCodeGrant: true,
},
},
authFlows: {
adminUserPassword: true,
userPassword: true,
},
generateSecret: true,
});
}
}
参考にしたサイト
Recommends
New Posts
Hot posts!
Date
Tags
(110)
(54)
(54)
(47)
(45)
(36)
(30)
(29)
(24)
(24)
(22)
(21)
(21)
(20)
(19)
(17)
(16)
(16)
(15)
(14)
(12)
(12)
(12)
(12)
(12)
(12)
(11)
(10)
(10)
(10)
(10)
(10)
(9)
(9)
(8)
(8)
(8)
(8)
(7)
(7)
(6)
(6)
(6)
(6)
(6)
(5)
(5)
(5)
(5)
(4)
Author