aws-samples / aws-cdk-intro-workshop

Introduction to the AWS CDK - Workshop
MIT No Attribution
304 stars 348 forks source link

CDK WorkShop Issue with cdk bootstrap command on Windows 7 Professional #173

Closed SomayaB closed 3 years ago

SomayaB commented 3 years ago

:question: Guidance Question

Originally posted by @Blyseur in https://github.com/aws/aws-cdk/issues/11010

In the CDK WorkShop, when we add our first lambda function, we have to import @aws-cdk/aws-lambda. Once, we write the code and we want to deploy, we have an error occured because of the bootstrapping

Reproduction Steps

On Windows, init a cdk project, follow the steps until arrived to the lambda function step. https://cdkworkshop.com/20-typescript/30-hello-cdk/200-lambda.html

What did you expect to happen?

Deploy correctly CdkWorkshopStack

What actually happened?

We obtain an error, where it is sayed we must deployed the toolkit stack.

IAM Statement Changes
┌───┬─────────────────────────────────┬────────┬────────────────┬──────────────────────────────┬───────────┐
│   │ Resource                        │ Effect │ Action         │ Principal                    │ Condition │
├───┼─────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${HelloHandler/ServiceRole.Arn} │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
└───┴─────────────────────────────────┴────────┴────────────────┴──────────────────────────────┴───────────┘
IAM Policy Changes
┌───┬─────────────────────────────┬────────────────────────────────────────────────────────────────────────────────┐
│   │ Resource                    │ Managed Policy ARN                                                             │
├───┼─────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${HelloHandler/ServiceRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
└───┴─────────────────────────────┴────────────────────────────────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)? y
CdkWorkshopStack: deploying...

 CdkWorkshopStack failed: Error: This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-account/unknown-region")
    at Object.addMetadataAssetsToManifest (C:\Users\Toto\AppData\Roaming\npm\node_modules\aws-cdk\lib\assets.ts:27:11)
    at Object.deployStack (C:\Users\Toto\AppData\Roaming\npm\node_modules\aws-cdk\lib\api\deploy-stack.ts:207:29)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at CdkToolkit.deploy (C:\Users\Toto\AppData\Roaming\npm\node_modules\aws-cdk\lib\cdk-toolkit.ts:180:24)
    at initCommandLine (C:\Users\Toto\AppData\Roaming\npm\node_modules\aws-cdk\bin\cdk.ts:197:9)
This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-account/unknown-region")

So, at this moment, we run cdk bootstrap and an other error occured :

 ⏳  Bootstrapping environment aws://unknown-account/unknown-region...
 ❌  Environment aws://unknown-account/unknown-region failed bootstrapping: [Error: ENOENT: no such file or directory, mkdtemp 'C:\Users\Toto\Documents\cdk-workshop\ASIA......\........\......\......\......\......\......\......\......\......\......\cdk-bootstrapXXXXXX'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'mkdtemp',
  path: 'C:\\Users\\Toto\\Documents\\cdk-workshop\\ASIA......\......\\......\\......\......\\......\\......\\......\\......\\......\\......\\......\\......\\......\\......\\cdk-bootstrapXXXXXX'
}
ENOENT: no such file or directory, mkdtemp 'C:\\Users\\Toto\\Documents\\cdk-workshop\\ASIA......\......\\......\\......\......\\......\\......\\......\\......\\......\\......\\......\\......\\......\\......\\cdk-bootstrapXXXXXX'

Environment

Other information

SomayaB commented 3 years ago

Hi @Blyseur, did you provide the environment (account and region) you want to deploy to? This can be done 3 ways.

  1. Directly in the command cdk bootstrap aws://ACCOUNT-NUMBER/REGION.

  2. Storing it in your aws profile and then using the basic cdk bootstrap command.

  3. Using environment variables and then again using the basic cdk bootstrap command.

You can read more about bootstrapping here. Key section:

If you do not specify at least one environment in the cdk bootstrap command, the AWS CDK Toolkit synthesizes the AWS CDK app in the current directory and bootstraps all the environments referenced in the app. If a stack is environment-agnostic (that is, it does not have an env property), the CDK's environment (for example, the one specified using --profile, or the default AWS environment otherwise) is applied to make the stack environment-specific, and that environment is then bootstrapped.

Blyseur commented 3 years ago

Hi @SomayaB yes, I did and I tried it with the same configuration on Linux, it worked correctly.

peterwoodworth commented 3 years ago

This isn't an issue with the workshop, if you're still having trouble with this please open an issue on the main repo

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.