diff --git a/packages/@aws-cdk/core/lib/asset-staging.ts b/packages/@aws-cdk/core/lib/asset-staging.ts index 89f7257ae522a..c948bc377c9a6 100644 --- a/packages/@aws-cdk/core/lib/asset-staging.ts +++ b/packages/@aws-cdk/core/lib/asset-staging.ts @@ -428,16 +428,6 @@ export class AssetStaging extends CoreConstruct { // Chmod the bundleDir to full access. fs.chmodSync(bundleDir, 0o777); - let user: string; - if (options.user) { - user = options.user; - } else { // Default to current user - const userInfo = os.userInfo(); - user = userInfo.uid !== -1 // uid is -1 on Windows - ? `${userInfo.uid}:${userInfo.gid}` - : '1000:1000'; - } - // Always mount input and output dir const volumes = [ { @@ -457,6 +447,16 @@ export class AssetStaging extends CoreConstruct { localBundling = options.local?.tryBundle(bundleDir, options); if (!localBundling) { + let user: string; + if (options.user) { + user = options.user; + } else { // Default to current user + const userInfo = os.userInfo(); + user = userInfo.uid !== -1 // uid is -1 on Windows + ? `${userInfo.uid}:${userInfo.gid}` + : '1000:1000'; + } + options.image.run({ command: options.command, user,