pulumi/pulumi · error · Error

'apply' is not allowed from inside a cloud-callback. Use 'ge

Error message

'apply' is not allowed from inside a cloud-callback. Use 'get' to retrieve the value of this Output directly.

What it means

Pulumi's Node.js SDK throws this when a program calls Output.apply() during closure serialization, i.e. inside a cloud callback (e.g. an AWS Lambda handler being captured). Inside such code, the captured Output's value is available directly, so apply() (which needs engine communication) is illegal. The SDK replaces captured Outputs with a SerializedOutput class whose apply() always throws.

Source

Thrown at sdk/nodejs/runtime/closure/createClosure.ts:296

    set?: (v: any) => void;
}

/**
 * {@link SerializedOutput} is the type we convert real deployment-time outputs
 * to when we serialize them into the environment for a closure.  The output
 * will go from something you call `apply` on to transform during deployment, to
 * something you call `.get` on to get the raw underlying value from inside a
 * cloud callback.
 *
 * IMPORTANT: Do not change the structure of this type. Closure serialization
 * code takes a dependency on the actual shape (including the names of
 * properties like `value`).
 */
class SerializedOutput<T> {
    public constructor(private readonly value: T) {}

    public apply<U>(func: (t: T) => Input<U>): Output<U> {
        throw new Error(
            "'apply' is not allowed from inside a cloud-callback. Use 'get' to retrieve the value of this Output directly.",
        );
    }

    public get(): T {
        return this.value;
    }
}

export interface ClosureInfo {
    func: FunctionInfo;
    containsSecrets: boolean;
}

/**
 * Serializes a function and its closure environment into a form that is
 * amenable to persistence as simple JSON. Like {@link toString}, it includes
 * the full text of the function's source code, suitable for execution. Unlike

View on GitHub (pinned to 793f7b2e16)

Solutions

  1. Inside the cloud callback, replace capturedOutput.apply(fn) with fn(capturedOutput.get())
  2. Move the .apply() call outside the callback into deployment-time code and capture only the resolved value
  3. If the value is a plain captured value, access it directly instead of through Output combinators

Example fix

// before
const handler = (ev) => bucketArn.apply(arn => use(arn));
// after
const handler = (ev) => use(bucketArn.get());
Defensive patterns

Strategy: validation

Validate before calling

function usesApplyInsideCallback(src: string): boolean { return /\.apply\s*\(/.test(src); }

Prevention

When it happens

Trigger: Calling output.apply(v => ...) inside a function that is serialized as a cloud callback (e.g. a lambda handler passed to aws.lambda.CallbackFunction or a serialized factory), where the output was captured via the closure mechanism.

Common situations: Using .apply() inside an event-handler function deployed as a serverless function; copying code that used .apply() in deployment-time code into a callback body; forgetting to call .get() on the captured SerializedOutput.

Related errors


AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31). Data as JSON: /api/errors/af3c1e28cfa86a34. Report an issue: GitHub.