https://pulumi.com logo
Title
w

wooden-animal-34285

05/03/2021, 5:46 PM
Hi, I'm trying out the Automation API and I am stuck as
createOrSelectStack()
blocks indefinitly. It does not timeout or writes any errors to the console.
export async function createInstance(): Promise<UpResult> {
    const program = programs.getProgram()

    // Create our stack
    const args: InlineProgramArgs = {
        stackName: "dev",
        projectName: "inlineNode",
        program,
    };

    // create (or select if one already exists) a stack that uses our local program
    <http://console.info|console.info>("initializing stack...");
    const stack = await pulumiAutoAPI.LocalWorkspace.createOrSelectStack(args, {

    });
    <http://console.info|console.info>("successfully initialized stack");

    <http://console.info|console.info>("setting up config");
    await stack.setConfig("aws:region", { value: "us-east-2" });
    <http://console.info|console.info>("config set");

    // is this step necessary because of the config step?
    // possible to setup config as part of create stack?
    <http://console.info|console.info>("refreshing stack...");
    await stack.refresh({ onOutput: <http://console.info|console.info> });
    <http://console.info|console.info>("refresh complete");

    <http://console.info|console.info>("updating stack...");
    const upRes = await stack.up({ onOutput: <http://console.info|console.info> });
    <http://console.info|console.info>(`update summary object: ${JSON.stringify(upRes.summary)}`);
    console.log(`update summary: \n${JSON.stringify(upRes.summary.resourceChanges, null, 4)}`);
    console.log(`outputs: ${JSON.stringify(upRes.outputs)}`);

    return upRes
}
I couldn't find any reference for such behaviour. Has anybody an idea what the cause could be? Thanks! System:
NodeJS: "14.16.1"
Pulumi: "3.1.0"
r

red-match-15116

05/03/2021, 5:53 PM
Are you sure that you have valid AWS credentials? This can possibly happen when you have AWS credentials that are expired. https://github.com/pulumi/pulumi-aws/issues/814
w

wooden-animal-34285

05/03/2021, 5:58 PM
Thx, for the fast response. I have double checked, the aws-cli works fine.
r

red-match-15116

05/03/2021, 6:03 PM
Yup, definitely sounds odd. Please open an issue with the code needed to reproduce the issue. This isn’t something that we’ve seen at all in our own usage of Automation API so you’ll need to be very specific about your setup.
👍 1
l

lemon-agent-27707

05/03/2021, 6:11 PM
Are you running the parent function in a try catch or with a promise exception handler?
w

wooden-animal-34285

05/03/2021, 6:25 PM
Thx Evan, seems like express doesn't forward exceptions
CommandError: code: 255
 stdout: 
 stderr: error: PULUMI_ACCESS_TOKEN must be set for login during non-interactive CLI sessions

 err?: 

    at Object.createCommandError (/home/secustor/repos/pulumi-automation-api/node_modules/@pulumi/pulumi/automation/errors.js:71:17)
    at ChildProcess.<anonymous> (/home/secustor/repos/pulumi-automation-api/node_modules/@pulumi/pulumi/automation/cmd.js:63:40)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
    at Process.callbackTrampoline (internal/async_hooks.js:131:14) {
  commandResult: CommandResult {
    stdout: '',
    stderr: 'error: PULUMI_ACCESS_TOKEN must be set for login during non-interactive CLI sessions\n',
    code: 255,
    err: undefined
  }
}
Is there a possibility to set an
onOutput
value as there is for
stack.up
?
l

lemon-agent-27707

05/03/2021, 6:45 PM
One thing to consider, automation api operations in nodejs return promises. These promises can reject and you need to handle errors accordingly. The try/catch error handling in the automation api express example might be a useful reference: https://github.com/pulumi/automation-api-examples/blob/main/nodejs/pulumiOverHttp-ts/index.ts#L63-L85
Is there a possibility to set an 
onOutput
 value as there is for 
stack.up
I don't think this is something we would support for all operations. update and other lifecycle operations are special as they can run for multiple minutes, produce useful incremental info that can be rendered to users, etc.