4

I am crafting a post trigger lambda function with NodeJS to move a newly registered user to a specific pool:

const AWS = require('aws-sdk');

const cognito = new AWS.CognitoIdentityServiceProvider();

export const hello = (event, context, callback) => {
  console.log(event);

  const params = {
    GroupName: 'ADMIN',
    Username: event.userName,
    UserPoolId: event.userPoolId,
  };

  cognito.adminAddUserToGroup(params, (err, data) => {
    if (err) {
      callback(err)
    }

    callback(null, event);
  });
};

My serverless.yml has iamRoleStatements added so the function has the right permissions (I think):

provider:
  name: aws
  runtime: nodejs8.10
  stage: dev
  region: us-east-1
  iamRoleStatements:
    - Effect: Allow
      Action:
      - cognito-sync:*
      - cognito-identity:*
      Resource: arn:aws:cognito-identity:*:*:*
    - Effect: Allow
      Action:
      - cognito-idp:*
      Resource: arn:aws:cognito-idp:*:*:*

Currently my error is:

An error occurred (InvalidLambdaResponseException) when calling the AdminConfirmSignUp operation: Invalid lambda function output : Invalid JSON

UPDATE:

It inexplicably started working with the same code. Go figure.

jkeys
  • 3,803
  • 11
  • 39
  • 63
ilrein
  • 3,833
  • 4
  • 31
  • 48
  • In your callbacks, can you try putting a random object instead of `err` and `event`? Just to get some type of response to see if the problem is with the `err` or `event`? – Charlie Fish Dec 28 '18 at 00:52
  • Where you use `AdminConfirmSignUp` function? – hoangdv Dec 28 '18 at 01:25

0 Answers0