Serverless + Cognito, adminAddUserToGroup post confirm lambda trigger

Viewed 1968

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.

0 Answers
Related