![[AWS CDK] Cognito を構築](/images/thumbnail/aws-logo.png)
[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
Author