これは私の cdk スクリプトです。
import * as cdk from '@aws-cdk/core';
import * as codecommit from "@aws-cdk/aws-codecommit";
import * as amplify from "@aws-cdk/aws-amplify";
import * as cognito from "@aws-cdk/aws-cognito";
import * as iam from "@aws-cdk/aws-iam";
export class CdkdeployStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Part 1 - Connect to Code Commit Repository
const codecommitRepo = codecommit.Repository.fromRepositoryName(
this,
"reactamplifyfullstackcdk",
"react-amplify-fullstack"
);
// Part 2 - Creation of the Amplify Application
const amplifyApp = new amplify.App(this, "reactamplifyfullstack", {
sourceCodeProvider: new amplify.CodeCommitSourceCodeProvider({
repository: codecommitRepo,
}),
});
const devBranch = amplifyApp.addBranch("dev");
//const qaBranch = amplifyApp.addBranch("qa");
//const stageBranch = amplifyApp.addBranch("stage");
// Creation of new Cognito UserPool
const userPool = new cognito.UserPool(
this,
"raf-userpool",
{
userPoolName: "reactamplifyfullstack_userpool",
selfSignUpEnabled: true,
autoVerify: {
email: true
},
signInAliases: {
email: true
}
}
);
const cfnUserPool = userPool.node.defaultChild as cognito.CfnUserPool;
cfnUserPool.policies = {
passwordPolicy: {
minimumLength: 8,
requireUppercase: true
}
};
//Creation of new Userpool client
const userPoolClient = new cognito.UserPoolClient(
this,
"reactamplifyfullstack_userpoolClient",
{
generateSecret: false,
userPool: userPool,
userPoolClientName: "reactamplifyfullstack_userpool_client_web"
}
);
//Creation of new Identity Pool
const identityPool = new cognito.CfnIdentityPool(
this,
"reactamplifyfullstack_identitypool",
{
allowUnauthenticatedIdentities: false,
cognitoIdentityProviders: [{
clientId: userPoolClient.userPoolClientId,
providerName: userPool.userPoolProviderName
}]
}
);
//Creation of new Authenticated Role for Identity Pool
const authenticatedRole = new iam.Role(
this,
"reactamplifyfullstack_auth_role",
{
assumedBy: new iam.FederatedPrincipal('cognit-identity.anazonaws.com', {
"StringEquals": {'cognit-identity.anazonaws.com:aud': identityPool.ref },
"ForAnyValue:StringLike": { 'cognit-identity.anazonaws.com:amr': "authenticated"},
}, "sts:AssumeRoleWithWebIdentity"),
}
);
//Add Policy to the IAM role
authenticatedRole.addToPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
"mobileanalytics:*",
"cognito-sync:*",
"cognito-identity:*"
],
resources: ['*']
}));
//Set Default policy
const defaultPolicy = new cognito.CfnIdentityPoolRoleAttachment(this, "DefaultValid", {
identityPoolId: identityPool.ref,
roles: {
"authenticated": authenticatedRole.roleArn
}
});
//CDK output
new cdk.CfnOutput(this, 'aws_project_region', { value: 'ap-south-1'});
new cdk.CfnOutput(this, 'aws_cognito_identity_pool_id', { value: identityPool.ref });
new cdk.CfnOutput(this, 'aws_cognito_region', { value: 'ap-south-1' });
new cdk.CfnOutput(this, 'aws_user_pools_id', { value: userPool.userPoolId });
new cdk.CfnOutput(this, 'aws_user_pools_web_client_id', { value:
userPoolClient.userPoolClientId });
new cdk.CfnOutput(this, 'oauth', { value: '{}' });
}
}
ビルドしようとすると、
npm run build
次のエラーを表示し、
***> cdkdeploy@0.1.0 ビルド
tsc lib/cdkdeploy-stack.ts:57:7 - エラー TS2345: タイプ 'this' の引数は、タイプ 'Construct' のパラメーターに割り当てられません。タイプ 'CdkdeployStack' は、タイプ 'Construct' に割り当てられません。プロパティ 'node' のタイプに互換性がありません。タイプ「import("/home/crypto/react/react-amplify-fullstack/cdkdeploy/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode」にプロパティ「addValidation」がありませんが、タイプには必要です'import("/home/crypto/react/react-amplify-fullstack/cdkdeploy/node_modules/@aws-cdk/aws-cognito/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'. 57 これ、~~~~ node_modules/@aws-cdk/aws-cognito/node_modules/@aws-cdk/core/lib/construct-compat.d.ts:439:5 439 addValidation(validation: constructs.IValidation):空所; ~~~~~~~~~~~~~ ここで「addValidation」を宣言します。lib/cdkdeploy-stack.ts:91:69 - エラー TS2345: タイプ 'this' の引数は、タイプ 'Construct' のパラメーターに割り当てられません。91 const defaultPolicy = new cognito.CfnIdentityPoolRoleAttachment(this, "DefaultValid", { ~~~~ 2 つのエラーが見つかりました。npm ERR! コード 2 npm ERR! パス /home/crypto/react/react-amplify-fullstack/cdkdeploy npm ERR! command failed npm ERR! command sh -c tsc npm ERR! この実行の完全なログは次の場所にあります: npm ERR! /home/crypto/.npm/_logs/2021-02-24T08_34_57_019Z-debug.log*** { ~~~~ 2 つのエラーが見つかりました。npm エラー! コード 2 npm ERR! path /home/crypto/react/react-amplify-fullstack/cdkdeploy npm ERR! コマンドが失敗しました npm ERR! コマンド sh -c tsc npm ERR! この実行の完全なログは、npm ERR! にあります。/home/crypto/.npm/_logs/2021-02-24T08_34_57_019Z-debug.log*** { ~~~~ 2 つのエラーが見つかりました。npm エラー! コード 2 npm ERR! path /home/crypto/react/react-amplify-fullstack/cdkdeploy npm ERR! コマンドが失敗しました npm ERR! コマンド sh -c tsc npm ERR! この実行の完全なログは、npm ERR! にあります。/home/crypto/.npm/_logs/2021-02-24T08_34_57_019Z-debug.log***
これを解決するのを手伝ってください。前もって感謝します。