https://pulumi.com logo
#general
Title
# general
b

brave-helicopter-9976

12/11/2018, 7:26 PM
I was just tinkering with Pulumi at the Node REPL and I ran into a couple discouraging issues. Is using the Pulumi JavaScript SDK in an interactive context —i.e., a console/REPL— an unsupported use case, or is it perhaps just not a priority? (Details follow; I wanted to put the TLDR up top 🙂) I’m using Pulumi 0.16.7 on macOS 10.14.2 and NodeJS 11.4.0, with both Pulumi and Node installed via Homebrew. I created a fresh project and stack with
pulumi new aws-javascript
and successfully previewed the changes. My original motivation for this was to experiment with calling the
getAmi
function to view some example result data, as well as its error behavior. My first attempt:
Copy code
$ node
> const aws = require("@pulumi/aws");
{ Error: Missing required configuration variable 'aws:region'
	please set a value using the command `pulumi config set aws:region <value>`
    at Object.requireWithDefault (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/utilities.ts:45:16)
    at exports.region.utilities.requireWithDefault (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/config/vars.ts:44:78)
    at Config.require (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/pulumi/config.js:141:19) __pulumiRunError: true, key: 'aws:region' }
After some digging into Pulumi’s source code, I eventually figured out that I needed to export
PULUMI_CONFIG='{"aws:config:region":"us-east-1"}'
. I progressed to a new error!
Copy code
$ PULUMI_CONFIG='{"aws:config:region":"us-east-1"}' node
> const aws = require("@pulumi/aws");
undefined
> aws.getAmi({owners: ["amazon"], filters: [{name: "name", values: ["amzn2-ami-hvm-2.*-x86_64.gp2"]}], mostRecent: true})
Promise {
  <pending>,
  domain:
   Domain {
     domain: null,
     _events:
      [Object: null prototype] {
        removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> (node:15240) UnhandledPromiseRejectionWarning: Error: Pulumi program not connected to the engine -- are you running with the `pulumi` CLI?
    at Object.getMonitor (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/pulumi/runtime/settings.js:87:19)
    at Object.<anonymous> (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/pulumi/runtime/invoke.js:51:40)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jtilles/Developer/Scratch/pulumi-experiment/node_modules/@pulumi/pulumi/runtime/invoke.js:17:58)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)
(node:15240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Since the second error didn’t look particularly debuggable (from the looks of it, I’m guessing I would need to launch a gRPC server in order to use the SDK from the REPL) I decided it was time to ask for help.
For posterity, I’ll reproduce here a response I got later from one of the Pulumi engineers:
Pulumi cannot currently be used from the Node REPL shell. The Node program needs to be able to talk to the Pulumi engine/CLI to coordinate the deployment. We are looking at a model that would allow driving things from a Node program (REPL or test suite) instead of the
pulumi
CLI as part of https://github.com/pulumi/pulumi/issues/2287, but there's no ETA currently.