Pål Brattberg
03/17/2021, 8:57 AMHttpUserPoolAuthorizer
from existing userPoolClient
and userPool
? I cannot seem to find any fromArn
or similar methods in CDK for this.Artem Kalantai
03/17/2021, 11:29 AMArtem Kalantai
03/17/2021, 11:29 AMconst userPool = cognito.UserPool.fromUserPoolId(this, "dinenation-users", "userPoolID");
const userPoolClient = cognito.UserPoolClient.fromUserPoolClientId(this, "dinenation-app", "clientId");
Artem Kalantai
03/17/2021, 11:29 AMimport * as cognito from "@aws-cdk/aws-cognito";
Artem Kalantai
03/17/2021, 11:30 AMdefaultAuthorizer: new apigAuthorizers.HttpUserPoolAuthorizer({
userPool,
userPoolClient,
}),
Pål Brattberg
03/17/2021, 4:43 PM...
resources:
Outputs:
CognitoUserPoolId:
Value:
Ref: CognitoUserPool
Export:
Name: ${self:custom.stage}-CognitoUserPoolId
CognitoUserPoolClientId:
Value:
Ref: CognitoUserPoolClient
Export:
Name: ${self:custom.stage}-CognitoUserPoolClientId
And then consume like this in my `sst-stack.js`:
this.userPool = cognito.UserPool.fromUserPoolId(this, 'existingUserPool', cdk.Fn.importValue(`${scope.stage}-CognitoUserPoolId`))
this.userPoolClient = cognito.UserPoolClient.fromUserPoolClientId(this, 'existingUserPoolClient', cdk.Fn.importValue(`${scope.stage}-CognitoUserPoolClientId`))
this.userPoolAuthorizer = new apigAuthorizers.HttpUserPoolAuthorizer({
userPool: this.userPool,
userPoolClient: this.userPoolClient
})
this.api = new apig.HttpApi(this, `Api_${id}`)
this.api.addRoutes({
path: `/${id}/secure-ping`,
methods: [apig.HttpMethod.GET],
integration: new apigIntegrations.LambdaProxyIntegration({
handler: this.pingFn
}),
authorizer: this.userPoolAuthorizer
})
Thanks again @Artem Kalantai!Artem Kalantai
03/17/2021, 4:45 PM