amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
985 stars 454 forks source link

Accessing "Cognito User Pool" From a Lambda Function #636

Closed BardiaN closed 6 years ago

BardiaN commented 6 years ago

Hi guys! I've been searching a lot and couldn't find any related answers to my problem, neither in your issues nor other forums. But I apology in advance if I'm asking a repeated question here. So, I'm working with AWS Cognito and everything on the frontend side is working fine. Now I need to have an admin part, so our admins would be able to manage users like updating their information or etc. I found "CognitoIdentityServiceProvider" on AWS SDK and for using that I created a new user on IAM and I assigned a "Cognito Power User" policy. It worked fine on my frontend, but due to the security reasons, I moved this part to our backend, so our Power Cognito User Credentials would be safer. Our backend is on AWS Lambda Functions deployed via Serverless. The exact same code which is working on my local network is failing on Lambda function with this error:

Inaccessible host: cognito-idp.us-east-1'. This service may not be available in theus-east-1,' region.

So I figured out it might have something to do with our Lambda package being on a different VPC. I already tried that but still the same error. I even tried giving "Admin" access policy to my Lambda Function Role, but it didn't work either. I already know that it's just an internal access matter, but I don't know how to solve it. I really need to know if it's possible to access Cognito Admin Functionality from Lambda Functions using AWS SDK CognitoIdentityServiceProvider at all. Thanks in advance for your time.

BardiaN commented 6 years ago

Sorry for bothering! Found the problem. I removed this line from my code and it's solved: AWS.config.region = 'us-east-1'; I'm not sure why it works fine out of AWS network, but you must not set the region in this case. Closed the Issue...