Serveless v1 with aws Cognito

I want to authenticate application users using cognito user pool with java script SDK. I have manually create account and user pool for my application . I want to configure API gate way authentication part through serverless.
How to do it?
Is there any alternative way for doing this?

Please mention example application for API gateway configuration.

1 Like

Hi,

We have working auth with Cognito user pool but it is still using Serverless 0.5.

First what you need is custom authorizer function: https://github.com/keboola/developer-portal/tree/master/authorizer - it is more or less copied from some aws tutorial. (API Gateway supports direct Cognito User pool authorizer however I didn’t find a way how to reference it from endpoint deifinition in Serverless.) Then you configure endpoints like this: https://github.com/keboola/developer-portal/blob/master/auth/me/s-function.json#L17

I’m not sure if I haven’t forgotten something, just ask if anything is not clear.

Jakub

3 Likes

currently i use server less v1. Can i move v1 to v0.5

I don’t think it is necessary, you just need to adjust our code for sls 1.0.

You should be able to set this up through custom resources: https://github.com/serverless/serverless/blob/master/docs/guide/custom-provider-resources.md

Currently cognito isn’t supported by Cloudformation, so we can’t set it up automatically.

If anyone manages to set it using custom resources I would be very grateful to see it. So far I have zero experience with Cloud Formation and don’t have a clue how to start so now I give up until Cognito is supported. ;o)