Question

SDK calls from AWS Lambda all timeout

  • 28 November 2022
  • 0 replies
  • 58 views

I’m using the 4.0 Javascript SDK from node based AWS Lambda. I can create a Looker session and login in my JS code, and retrieve tokens, so the session works fine. However, every single call to the SDK itself (sdk.search_users, skd.create_user, sdk.me,...) all timeout with no error, no docs, nothing but ETIMEOUT.

The exact same code can be extracted from my lambda and run locally on my laptop, so the code, the url and the credentials are all verified as correct. And as I mentioned the session login works in exactly the same way in both environments, so I know that a connection from lambda to Looker can be established. The issue seems to be purely related to the sdk calls. API Explorer also works perfectly.

 

At this point I can only think of 2 possible issues:
 - Looker itself is not accepting sdk calls from lambdas for some reason..

 - The API URL set in the Looker admin panel is wrong, but again I’ve tried multiple variants, and https://:<INSTACNE_NAME>:443, or   https://:<INSTACNE_NAME>:1999 both work locally when set as LOOKERSDK_BASE_URL, and when set in the Admin panel, so I’m at a loss as to where the issue is.

 

Looker support have been singulalry unhelpful - every time I’ve reached out to the chat service I get answers along the lines of “we don’t answer SDK questions here”, or a link to something completely unrelated.

 

Sample code attached below if it helps, any directions on this would be much appreciated.

 

/* eslint-disable consistent-return */
/* eslint-disable no-restricted-syntax */
const { Looker40SDK, environmentPrefix } = require('@looker/sdk');
const { NodeSession, NodeSettings } = require('@looker/sdk-node');

const { LOOKERSDK_BASE_URL, LOOKERSDK_CLIENT_ID, LOOKERSDK_CLIENT_SECRET} = process.env;

exports.handler = wrap(async (event) => {

if (!event?.userList) {
logger.error('No User List provided');
return null;
}
const { userList } = event;
logger.info(`LOOKERSDK_BASE_URL : ${LOOKERSDK_BASE_URL}`);
logger.info(`LOOKERSDK_CLIENT_ID : ${LOOKERSDK_CLIENT_ID}`);
logger.info(`LOOKERSDK_CLIENT_SECRET : ${LOOKERSDK_CLIENT_SECRET}`);

logger.info(`UserList: ${JSON.stringify(userList)}`);

const settings = new NodeSettings(environmentPrefix);
const session = new NodeSession(settings);
const token = await session.login();
logger.info(`Session login tokens: ${JSON.stringify(token)}`);
const sdk = new Looker40SDK(session);

const sessionStatus = await sdk.authSession.isAuthenticated();
logger.info(`SESSION STATUS: ${JSON.stringify(sessionStatus)}`);

// Create Users
userList.forEach(async (user) => {
try {
logger.info(`Check for existing User ${user.id} with email: ${user.email}`);
const existingUsers = await sdk.search_users({
email: user.email
});
logger.info(`Existing users list: ${JSON.stringify(existingUsers)}`);

if (!existingUsers.length) {
logger.info('Creating Looker user....');

const lookerUser = await sdk.ok(sdk.create_user(
{
body: {
first_name: user.firstName,
is_disabled: false,
last_name: user.firstName,
models_dir_validated: false
}
}));
const { id: lookerId } = lookerUser;
logger.info(`Looker User Created for User: ${user.id} -> ${lookerId}`);
await sdk.ok(
sdk.create_user_credentials_email(
lookerId,
{ email: user.email }
));
logger.info('Email added');

await sdk.ok(
sdk.add_group_user(
8,
{ user_id: lookerId }));
logger.info('Group attribute set');

} else {
logger.info('User already exists');
}
} catch (error) {
logger.error(`Error creating Looker user: ${JSON.stringify(error)}`);
return {
statusCode: 503,
headers: {
...event.headers,
},
body: JSON.stringify(error),
isBase64Encoded: false,
};
}
});

return {
statusCode: 200,
headers: {
...event.headers,
},
body: 'Looker users created',
isBase64Encoded: false,
};
});

 


0 replies

Be the first to reply!

Reply