Skip to content

If no home directory exist on host, the CDK will fail  #7530

@NetaNir

Description

@NetaNir

The CDK creates an account cache in:

~/.cdk/cache

When running in an environment that does no have a home directory, such as aws-lambda, attempting to create the cache will fail synth/deploy/diff.

Reproduction Steps

Execute the CDK inside a lambda which defines AWS credentials using AWS environment variables.

Error Log

Toolkit stack: CDKToolkit
Setting "CDK_DEFAULT_REGION" environment variable to us-west-2
Resolving default credentials
Looking up default account ID from STS
Default account ID: xxxxx
EACCES: permission denied, mkdir '/home/xxxx'
Error: EACCES: permission denied, mkdir '/home/xxx'
2020-04-23T03:11:28.801Z        fc4cb3ae-5a84-1734-2972-7f101accf659    INFO    Error: child exited with code 1
    at ChildProcess.<anonymous> (/var/task/node_modules/await-spawn/index.js:28:21)
    at ChildProcess.emit (events.js:311:20)
    at ChildProcess.EventEmitter.emit (domain.js:482:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
  code: 1,
  stderr: ''
}

Environment

  • CLI Version : 1.34
  • Framework Version: 1.34
  • OS :
  • Language : typescript

Other

A way around this is setting the HOME environment variable to a directory which exist, and the user has permission on (the user running cdk), courtesy of @rhboyd:

const main = async () => {
  process.env.HOME = '/tmp';
  const bl = await spawn('node', ['node_modules/aws-cdk/bin/cdk.js', '--app', '"node dist/sample-app.js"', 'synth', '--verbose', '--output', '/tmp', '--no-staging'], { stdio: ['pipe', 'pipe', process.stderr] });
  console.log(bl.toString())
}

Metadata

Metadata

Labels

bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions