[AWS CDK] Cognito を構築
約 4 分
目次
概要
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,
});
}
}
参考にしたサイト
おすすめの記事
最新の記事
よく読まれている記事
タグから探す
- javascript130
- typescript67
- node.js54
- linux54
- 画像処理48
- amazon-aws48
- アルゴリズム37
- canvas35
- html529
- 画像処理100本ノック27
- php24
- centos24
- python22
- 競技プログラミング21
- mac21
- mysql20
- opencv17
- 雑談16
- 機械学習16
- docker16
- wordpress15
- atcoder14
- apache12
- データベース12
- amazon-s312
- red-hat12
- prisma12
- ubuntu11
- github10
- git10
- react10
- mariadb10
- vue.js9
- next.js9
- aws-cdk9
- css38
- 可視化8
- 小ネタ8
- nestjs8
- amazon-lightsail7
- ブログ6
- cms6
- oracle6
- perl6
- gitlab6
- iam5
- amazon-ec25
- 資格試験5
- aws-amplify5
- curl4