Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] cfn exec policies error and specify profile #10

Merged
merged 6 commits into from
Oct 8, 2020

Conversation

RichardDRJ
Copy link
Contributor

The updated version of CDK requires that Cloudformation execution policies are passed in for the toolkit stack. By default, we're okay to set this as AdministratorAccess, but I've added the ability for a user to specify it under provider in serverless.yml too.

Also, we shouldn't rely on AWS creds before we even log in with AWS creds - useful e.g. if the user sets a profile. Previously, we used the STS client directly to get acct ID. Now, we get default acct ID from the SDK provider or pull from provider.accountId if specified.

The updated version of CDK requires that Cloudformation execution policies are passed in for the toolkit stack. By default, we're okay to set this as AdministratorAccess, but I've added the ability for a user to specify it under `provider` in `serverless.yml` too.

Also, we shouldn't rely on AWS creds before we even log in with AWS creds - useful e.g. if the user sets a profile. Previously, we used the STS client directly to get acct ID. Now, we get default acct ID from the SDK provider or pull from `provider.accountId` if specified.
@RichardDRJ
Copy link
Contributor Author

Also applied prettier to touched files - not intentional, but not a bad thing 🤷

@revmischa
Copy link
Contributor

Terrific, thank you so much!

@RichardDRJ
Copy link
Contributor Author

Does that solve your issue? If so, I'll try to get it merged and released tomorrow morning UK time 🙂 And if it doesn't, feel free to ping over any other errors you hit and I'm happy to see what I can do!

@revmischa
Copy link
Contributor

revmischa commented Oct 7, 2020

Now this:

  - /Users/cyber/dev/jb/serverless-aws-cdk/cdk/serverlessStack.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/cdk/app.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/cdk/toolkit.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/cdk/deployStack.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/deploy/awsCdkDeploy.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/deploy/index.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/index.js
  - /Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/classes/PluginManager.js
  - /Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/Serverless.js
  - /Users/cyber/.nvm/versions/node/v12.16.3/lib/node_modules/serverless/lib/Serverless.js
  - /Users/cyber/.nvm/versions/node/v12.16.3/lib/node_modules/serverless/scripts/serverless.js
  - /Users/cyber/.nvm/versions/node/v12.16.3/lib/node_modules/serverless/bin/serverless.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
      at Function.Module._load (internal/modules/cjs/loader.js:840:27)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/serverlessStack.ts:5:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/app.ts:3:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/toolkit.ts:6:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/deployStack.ts:1:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/deploy/awsCdkDeploy.ts:6:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/deploy/index.ts:1:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at Object.<anonymous> (/Users/cyber/dev/jb/serverless-aws-cdk/index.ts:8:1)
      at Module._compile (internal/modules/cjs/loader.js:1133:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
      at Module.load (internal/modules/cjs/loader.js:977:32)
      at Function.Module._load (internal/modules/cjs/loader.js:877:14)
      at Module.require (internal/modules/cjs/loader.js:1019:19)
      at require (internal/modules/cjs/helpers.js:77:18)
      at requireServicePlugin (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/classes/PluginManager.js:27:12)
      at /Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/classes/PluginManager.js:144:20
      at Array.map (<anonymous>)
      at PluginManager.resolveServicePlugins (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/classes/PluginManager.js:141:8)
      at PluginManager.loadAllPlugins (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/classes/PluginManager.js:127:40)
      at /Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless/lib/Serverless.js:88:39
      at tryCatcher (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/bluebird/js/release/promise.js:547:31)```
Tried `npm i uuid` but it doesn't seem to help

@RichardDRJ
Copy link
Contributor Author

RichardDRJ commented Oct 7, 2020

Hm, looks like uuid is definitely included in the serverless-aws-cdk package.json. How're you invoking sls? I've found in the past it can be really weird if you invoke a global (or per-user) version, so as long as you have sls in your project's package.json, you can add an entry "sls": "tsc && sls" to the package.json scripts block, and then invoke with npm run sls -- {{ARGS}}.

For example:

    "scripts": {
        // ... other scripts

        "sls": "tsc && sls",

        // ... other scripts
    },

Just to check, is there a uuid folder in your node_modules folder?

@revmischa
Copy link
Contributor

I installed latest global and local sls, sls will use sls from local node_modules in recent versions. I have node_modules/uuid

I had serverless-aws-cdk npm linked though and after running npm i in that local copy it fixed the uuid dependency.

And now it deploys! Thanks for all your help! This is fabulous

@revmischa
Copy link
Contributor

Well it created the stack. After building my infra it spat out:

Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...
error TS5055: Cannot write file '/Users/cyber/dev/jb/mercury/packages/backend/build/cdk/database.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cyber/dev/jb/mercury/packages/backend/build/cdk/index.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cyber/dev/jb/mercury/packages/backend/build/src/api/User.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cyber/dev/jb/mercury/packages/backend/build/src/db/Connection.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/Users/cyber/dev/jb/mercury/packages/backend/build/src/index.d.ts' because it would overwrite input file.

@RichardDRJ
Copy link
Contributor Author

@revmischa Just to check, was the above issue fixed by #12?

@revmischa
Copy link
Contributor

The CfnRole issue is fixed yes, thanks a million for your help with that

@RichardDRJ
Copy link
Contributor Author

Great, and has it stopped emitting the error TS5055: Cannot write file errors?

@revmischa
Copy link
Contributor

Great, and has it stopped emitting the error TS5055: Cannot write file errors?

I think this helped that #12

Problem may be related to running with npm link locally, not sure. Eager to try again with the next version of the npm package when you publish it.

@RichardDRJ RichardDRJ merged commit 54ae8d2 into master Oct 8, 2020
@RichardDRJ RichardDRJ deleted the fix/cfn-execution-policies branch October 8, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants