Ernie Francis
02/18/2022, 2:48 PMTypeError: Cannot read properties of undefined (reading 'UserPool')
at new BipStack (C:\Users\Asus\Documents\GitHub\bip\aws-backend\stacks\BipStack.ts:23:34)
at Object.main (C:\Users\Asus\Documents\GitHub\bip\aws-backend\stacks\index.ts:17:3)
at Object.<anonymous> (C:\Users\Asus\Documents\GitHub\bip\aws-backend\.build\run.js:94:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Frank
Ernie Francis
02/18/2022, 4:06 PMErnie Francis
02/18/2022, 4:07 PMimport * as sst from '@serverless-stack/resources';
import cognito, { UserPool } from 'aws-cdk-lib/aws-cognito';
export default class BipStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props);
// Create the table
// example schema
const table = new sst.Table(this, 'User', {
fields: {
id: sst.TableFieldType.STRING,
bipCount: sst.TableFieldType.NUMBER,
descirption: sst.TableFieldType.STRING,
binaryThingy: sst.TableFieldType.BINARY,
},
primaryIndex: { partitionKey: 'id' },
});
// Authentication
// create userpool
const userPool = new cognito.UserPool(this, 'UserPool', {
selfSignUpEnabled: true,
signInAliases: { email: true, phone: true },
});
// create userpool client
const userPoolClient = new cognito.UserPoolClient(this, 'UserPoolClient', {
userPool: userPool,
authFlows: {
userPassword: true,
custom: true,
},
});
// create google identity provider
new cognito.UserPoolIdentityProviderGoogle(this, 'Google', {
clientId: 'redacted',
clientSecret: 'redacted',
userPool: userPool,
attributeMapping: {
email: cognito.ProviderAttribute.GOOGLE_EMAIL,
givenName: cognito.ProviderAttribute.GOOGLE_GIVEN_NAME,
familyName: cognito.ProviderAttribute.GOOGLE_FAMILY_NAME,
},
});
//create AUTH
const auth = new sst.Auth(this, 'Auth', {
cognito: {
userPool,
userPoolClient,
},
});
// Create a HTTP API
const api = new sst.Api(this, 'Api', {
defaultFunctionProps: {
// Pass in the table name to our API
environment: {
tableName: table.dynamodbTable.tableName,
},
},
routes: {
'GET /users': 'src/lambdas/usermanager.handler',
'GET /sharpsports': 'src/lambdas/sharpsports.handler',
'POST /sharpsports': 'src/lambdas/sharpsports.handler',
},
});
// allow lambda to access the DynamoDB table
api.attachPermissions([table]);
// authenticate access to lambda routes
auth.attachPermissionsForAuthUsers([api]);
// Show the endpoint in the output
this.addOutputs({
ApiEndpoint: api.url,
UserPoolId: auth.cognitoUserPool!.userPoolId,
IdentityPoolId: auth.cognitoCfnIdentityPool.ref,
UserPoolClientId: auth.cognitoUserPoolClient!.userPoolClientId,
});
}
}
Frank
import * as cognito from 'aws-cdk-lib/aws-cognito';
Ernie Francis
02/18/2022, 5:18 PMErnie Francis
02/18/2022, 5:19 PM