George Evans
09/01/2021, 3:51 PMFrank
Frank
George Evans
09/01/2021, 3:55 PMGeorge Evans
09/01/2021, 3:55 PMCOGNITO_USER_POOL_ID: props.auth.cognitoUserPool.userPoolId
George Evans
09/01/2021, 3:56 PMError: 'georgeevans-decarbonisation-Auth' depends on 'georgeevans-decarbonisation-ApiStack' (georgeevans-decarbonisation-Auth -> georgeevans-decarbonisation-ApiStack/RestApi/Api/Resource.Ref). Adding this dependency (georgeevans-decarbonisation-ApiStack -> georgeevans-decarbonisation-Auth/UserPool/Resource.Ref) would create a cyclic reference.
George Evans
09/01/2021, 4:00 PMCOGNITO_USER_POOL_ID: ssm.StringParameter.valueFromLookup(this, `${scope.stage}-${scope.name}-cognitoUserPoolId`),
COGNITO_USER_POOL_ID: cdk.Fn.importValue(`${scope.stage}-${scope.name}-cognitoUserPoolId`),
George Evans
09/01/2021, 4:00 PMFrank
Auth
stack is dependent on the Api’s id from the Api
stack; and the Api
stack is dependent on the User pool id from the Auth
stack.Frank
Frank
George Evans
09/01/2021, 4:11 PMGeorge Evans
09/01/2021, 4:12 PMconst userPool = new cognito.UserPool(
this, "UserPool", {
userPoolName: `${scope.stage}-${scope.name}-users`,
standardAttributes: { email: { required: true } },
passwordPolicy: { tempPasswordValidity: cdk.Duration.days(90) },
signInCaseSensitive: false,
signInAliases: { email: true }
}
);
const userPoolClient = new cognito.UserPoolClient(this, "UserPoolClient", {
userPool,
disableOAuth: true
});
this.auth = new Auth(this, "CognitoAuth", {
cognito: {
triggers: { customMessage: "services/core/src/cognito/custom-message.handler" },
userPool,
userPoolClient
}
});
George Evans
09/01/2021, 4:12 PMFrank
auth.attachPermissionsForAuthUsers([api]);
The auth construct needs the api’s id to create it’s policy.George Evans
09/01/2021, 4:13 PMFrank
George Evans
09/01/2021, 4:14 PMGeorge Evans
09/01/2021, 4:18 PM{
"Action": "execute-api:Invoke",
"Resource": "arn:aws:execute-api:eu-west-2:193471113837:zbbio4r583/*",
"Effect": "Allow"
},
Frank
George Evans
09/01/2021, 4:22 PMFrank
auth.attachPermissionsForAuthUsers([api]);
Can you try this
const policy = new iam.Policy(this, "AuthPolicy", {
statements: [
new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: ["execute-api:Invoke"],
resources: [`arn:aws:execute-api:${scope.region}:${scope.account}:${api.httpApiId}/*`]
})
],
});
policy.attachToRole(auth.iamAuthRole);
George Evans
09/01/2021, 4:33 PMGeorge Evans
09/01/2021, 4:41 PMFrank
Frank
George Evans
09/02/2021, 8:30 AMmax.suster
09/12/2021, 6:06 AMauth.addPermissionsToAuthRole
. I hope its OK that I raise my question here.
Essentially, I have already deployed my Auth sst stack with Cognito User Pools and its working fine for my ReactStaticApp. However, now I have a separate Infrastructure repository in which I created an Api sst stack, but I am struggling to use the same Cognito User pools already deployed for the React app. I have been trying to add IAM authentication (from the already existing User pool) to the Api SST stack by doing something very similar to the solution reported in this thread. My solution gets deployed ok, but does not seem to work (I get HTTP 403 when using my existing Cognito User credentials). I assume this might not work without being able to refer to an instance of the Auth stack?
What do you suggest as a solution for reusing an existing Auth/Cognito pools for an Api sst that is deployed in a separate repository?Frank