Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.
Gen1 DocsLegacy

Page updated Dec 3, 2025

CDKでAmplifyが生成したCognitoリソースを変更する

Amplify Authは、基になるAmazon Cognitoリソース定義に対して合理的なデフォルト値を提供します。AWS Cloud Development Kit (CDK)を使用して直接リソースを変更することで、認証リソースをカスタマイズし、ユースケースに合わせて正確に動作するようにできます。

Cognito UserPoolのパスワードポリシーをオーバーライドする

L1のcfnUserPool構造を使用してaddPropertyOverrideを追加することで、パスワードポリシーをオーバーライドできます。

amplify/backend.ts
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';
const backend = defineBackend({
auth,
});
// L1 CfnUserPoolリソースを抽出
const { cfnUserPool } = backend.auth.resources.cfnResources;
// cfnUserPoolポリシーを直接変更
cfnUserPool.policies = {
passwordPolicy: {
minimumLength: 10,
requireLowercase: true,
requireNumbers: true,
requireSymbols: true,
requireUppercase: true,
temporaryPasswordValidityDays: 20,
},
};

Cognito UserPoolをオーバーライドしてパスワードレスサインイン方法を有効にする

推奨アプローチ: パスワードレス認証は、CDKオーバーライドを必要とせずにdefineAuthで直接設定できるようになりました。パスワードレス認証の設定方法を学びます

高度なユースケースでは、CDKオーバーライドを使用して基になるCognitoユーザープールリソースを変更して、パスワードレス方法でのサインインを有効にできます。パスワードレスサインイン方法の詳細を確認します

また、Cognitoドキュメントでパスワードレス認証フローの実装方法の詳細を確認することもできます。

amplify/backend.ts
import { defineBackend } from "@aws-amplify/backend"
import { auth } from "./auth/resource"
const backend = defineBackend({
auth,
})
const { cfnResources } = backend.auth.resources;
const { cfnUserPool, cfnUserPoolClient } = cfnResources;
// USER_AUTHで許可する認証要素を指定
cfnUserPool.addPropertyOverride(
'Policies.SignInPolicy.AllowedFirstAuthFactors',
['PASSWORD', 'WEB_AUTHN', 'EMAIL_OTP', 'SMS_OTP']
);
// USER_AUTHフローはパスワードレスサインインに使用
cfnUserPoolClient.explicitAuthFlows = [
'ALLOW_REFRESH_TOKEN_AUTH',
'ALLOW_USER_AUTH'
];
/* WebAuthnに必要 */
// WebAuthnRelyingPartyIDはrequesting party(例:「example.domain.com」)のドメイン
cfnUserPool.addPropertyOverride('WebAuthnRelyingPartyID', '<RELYING_PARTY>');
cfnUserPool.addPropertyOverride('WebAuthnUserVerification', 'preferred');