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

Infrastructure compile type checking errors #11

Closed
revmischa opened this issue Oct 7, 2020 · 19 comments
Closed

Infrastructure compile type checking errors #11

revmischa opened this issue Oct 7, 2020 · 19 comments

Comments

@revmischa
Copy link
Contributor

import { api } from "serverless-aws-cdk"
import { CfnOutput, Construct, Duration } from "@aws-cdk/core"
import { Vpc, SubnetType } from "@aws-cdk/aws-ec2"
import {
  ServerlessCluster,
  ParameterGroup,
  DatabaseClusterEngine,
  SubnetGroup,
  AuroraCapacityUnit,
} from "@aws-cdk/aws-rds"
import * as cdk from "@aws-cdk/core"
import { Secret } from "@aws-cdk/aws-secretsmanager"

export class AuroraSlsStack extends api.InfrastructureConstruct {
  constructor(scope: cdk.Construct, id: string, props: api.InfrastructureProps) {
    super(scope, id, props)

    const self = (this as unknown) as Construct  // otherwise type checks fail with `this`

    // create vpc
    const vpc = new Vpc(self, "Vpc", {
      cidr: "10.99.0.0/16",
      natGateways: 0,
      subnetConfiguration: [{ name: "aurora_isolated_", subnetType: SubnetType.ISOLATED }],
    })

    // get subnetids from vpc
    const subnetIds: string[] = []
    vpc.isolatedSubnets.forEach((subnet) => {
      subnetIds.push(subnet.subnetId)
    })

    // output subnet ids
    new CfnOutput(self, "VpcSubnetIds", {
      value: JSON.stringify(subnetIds),
    })

    // output security group
    new CfnOutput(self, "VpcDefaultSecurityGroup", {
      value: vpc.vpcDefaultSecurityGroup,
    })

    // create subnetgroup
    const dbSubnetGroup = new SubnetGroup(self, "AuroraSubnetGroup", {
      description: "Subnet group to access aurora",
      vpc: vpc,
      vpcSubnets: vpc.selectSubnets({
        subnetType: SubnetType.PRIVATE,
      }),
    })

    // create secret
    const dbSecret = new Secret(self, "AuroraDBSecret", {
      secretName: "/" + [props.stackName, "aurora"].join("/"),
      generateSecretString: {
        generateStringKey: "password",
        secretStringTemplate: '{"username": "dbadmin"}',
        passwordLength: 20,
        excludeCharacters: " %+:;{}",
      },
    })

    // create aurora db serverless cluster
    const aurora = new ServerlessCluster(self, "MercuryAuroraDB", {
      deletionProtection: false, // change me!
      clusterIdentifier: "mercury",
      defaultDatabaseName: "mercury",
      engine: DatabaseClusterEngine.AURORA_POSTGRESQL,
      subnetGroup: dbSubnetGroup,
      enableHttpEndpoint: true,
      parameterGroup: ParameterGroup.fromParameterGroupName(self, "ParameterGroup", "default.aurora-postgresql10"),
      scaling: {
        autoPause: Duration.days(4),
        minCapacity: AuroraCapacityUnit.ACU_2,
        maxCapacity: AuroraCapacityUnit.ACU_8,
      },
      vpc: vpc,
    })

    // const secretDBAttachment = new secretsmanager.SecretTargetAttachment(this, "MercuryDBSecretAttachment", {
    //   secret: dbSecret,
    //   target: aurora.asSecretAttachmentTarget(),
    // })

    //wait for subnet group to be created
    // aurora.addDependsOn(dbSubnetGroup)

    // construct arn from available information
    const account = props.env?.account
    const region = props.env?.region

    new CfnOutput(self, "AuroraClusterArn", {
      exportName: `${props.env}`,
      value: `arn:aws:rds:${region}:${account}:cluster:${aurora.clusterIdentifier}`,
    })
    new CfnOutput(self, "AuroraSecretArn", {
      exportName: `${props.env}`,
      value: dbSecret.secretArn,
    })
  }
}
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(2,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
../../../serverless-aws-cdk/cdk/toolkitStack.ts(1,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
../../../serverless-aws-cdk/deploy/awsCdkDeploy.ts(2,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
../../../serverless-aws-cdk/remove/awsCdkRemove.ts(2,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
../../../serverless-aws-cdk/diff/awsCdkDiff.ts(2,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
../../../serverless-aws-cdk/compile/awsCdkCompile.ts(2,29): error TS7016: Could not find a declaration file for module 'serverless'. '/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/serverless/lib/Serverless.js' implicitly has an 'any' type.
  Try `npm install @types/serverless` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless';`
cdk/index.ts(7,11): error TS2345: Argument of type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").Construct' is not assignable to parameter of type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").Construct'.
  Types of property 'node' are incompatible.
    Type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
      Types have separate declarations of a private property 'host'.
cdk/index.ts(9,24): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'Infrastructure' is not assignable to type 'Construct'.
    Types of property 'node' are incompatible.
      Type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
        Types have separate declarations of a private property 'host'.
cdk1/database.ts(16,11): error TS2345: Argument of type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").Construct' is not assignable to parameter of type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").Construct'.
cdk1/database.ts(53,33): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'AuroraSlsStack' is not assignable to type 'Construct'.
    Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.
cdk1/database.ts(71,61): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.

  Error --------------------------------------------------

  Error: TypeScript compilation failed
      at AwsCdkCompile.compile (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/compile.ts:11:15)
      at AwsCdkCompile.tryCatcher (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromiseCtx (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/promise.js:641:10)
      at _drainQueueStep (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/async.js:97:12)
      at _drainQueue (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/bluebird/js/release/async.js:15:14)
      at processImmediate (internal/timers.js:456:21)
      at process.topLevelDomainCallback (domain.js:137:15)
@revmischa
Copy link
Contributor Author

npm i form-data@latest
and
npm i --save-dev @types/serverless
helped a bit

Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(33,72): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Aws'.
  Type 'AwsCdkProvider' is missing the following properties from type 'Aws': naming, getProviderName, getServerlessDeploymentBucketName, request
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(35,45): error TS2339: Property 'package' does not exist on type 'Service'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(37,29): error TS2339: Property 'package' does not exist on type 'Service'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(43,25): error TS2339: Property 'consoleLog' does not exist on type '{ log(message: string): null; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(154,40): error TS2339: Property 'stackName' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(155,34): error TS2339: Property 'service' does not exist on type 'Service'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(160,45): error TS2339: Property 'stackTags' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(164,45): error TS2339: Property 'cfnRole' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(168,5): error TS2322: Type 'Service' is not assignable to type 'string'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(173,8): error TS2339: Property 'deploymentBucket' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(188,40): error TS2339: Property 'tsConfigPath' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(210,40): error TS2339: Property 'artifact' does not exist on type 'Service'.
../../../serverless-aws-cdk/provider/awsCdkProvider.ts(211,38): error TS2339: Property 'artifact' does not exist on type 'Service'.
../../../serverless-aws-cdk/cdk/toolkitStack.ts(10,33): error TS2339: Property 'toolkitStackName' does not exist on type '{ compiledCloudFormationTemplate: { Resources: { [key: string]: any; }; Outputs?: { [key: string]: any; } | undefined; }; name: string; stage: string; region: string; runtime?: string | undefined; timeout?: number | undefined; versionFunctions: boolean; }'.
../../../serverless-aws-cdk/deploy/awsCdkDeploy.ts(18,5): error TS2740: Type 'Aws' is missing the following properties from type 'AwsCdkProvider': options, serverless, tsCompiled, sdkProvider, and 24 more.
../../../serverless-aws-cdk/remove/awsCdkRemove.ts(16,5): error TS2322: Type 'Aws' is not assignable to type 'AwsCdkProvider'.
../../../serverless-aws-cdk/diff/awsCdkDiff.ts(17,5): error TS2322: Type 'Aws' is not assignable to type 'AwsCdkProvider'.
../../../serverless-aws-cdk/compile/awsCdkCompile.ts(17,5): error TS2322: Type 'Aws' is not assignable to type 'AwsCdkProvider'.

@RichardDRJ
Copy link
Contributor

That's odd - you shouldn't need to install @types/serverless, because serverless-aws-cdk includes its own .d.ts file (types/serverless.d.ts) to get rid of exactly an error you mentioned above: error TS7016: Could not find a declaration file for module 'serverless'

Could you check that you've still got that file in your copy? I've checked and it's definitely in master of this repo, and in node_modules when I install serverless-aws-cdk into a project on my local machine

@revmischa
Copy link
Contributor Author

Yeah I have that file. I seem to be getting all kinds of different errors trying to use my local npm linked version of the plugin. Currently:

Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...

  Error --------------------------------------------------

  Error: ENOENT: no such file or directory, stat '/Users/cyber/dev/jb/mercury/packages/backend/.build/.serverless/mercury.zip'
      at Object.statSync (fs.js:933:3)

I don't know where .build/ is coming from

@RichardDRJ
Copy link
Contributor

Hey @revmischa, just published 0.7.0. I'd be interested to know if that fixes these issues?

@revmischa
Copy link
Contributor Author

Installed it, here's where I'm at right now:

❯ rm -rf .build .serverless
❯ sls deploy
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: DOTENV: Loading environment variables from .env.development:
Serverless: 	 - STAGE
Serverless: 	 - AWS_XRAY_CONTEXT_MISSING
Serverless: 	 - DB_HOST
Serverless: 	 - DB_NAME
Serverless: Configuration warning: Unrecognized provider 'aws-cdk'
Serverless:
Serverless: You're relying on provider plugin which doesn't provide a validation schema for its config.
Serverless: Please report the issue at its bug tracker linking: https://www.serverless.com/framework/docs/providers/aws/guide/plugins#extending-validation-schema
Serverless: You may turn off this message with "configValidationMode: off" setting
Serverless:
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Trusted accounts:
Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...

  Error --------------------------------------------------

  Error: ENOENT: no such file or directory, stat '/Users/cyber/dev/jb/mercury/packages/backend/.build/.serverless/mercury.zip'
      at Object.statSync (fs.js:915:3)
      at Object.statSync (/usr/local/lib/node_modules/serverless/node_modules/graceful-fs/polyfills.js:308:16)

Wondering if this error is related to serverless/serverless-plugin-typescript#170

@revmischa
Copy link
Contributor Author

revmischa commented Oct 8, 2020

I'm trying the more maintained fork https://www.npmjs.com/package/@kingdarboja/serverless-plugin-typescript but still seeing the same error. Maybe we have competing tsconfig files? Or plugin-ts is deleting the .build dir before aws-cdk tries to use it or something?

.build/.serverless/mercury.zip seems fishy

@RichardDRJ
Copy link
Contributor

Interesting - when it fails, does .build no longer exist?

@revmischa
Copy link
Contributor Author

Yes, .build is gone. I do have mercury.zip inside .serverless though. Maybe the tsconfig from sls-plugin-ts is making the CDK compiler think outputs live in .build?

@RichardDRJ
Copy link
Contributor

I've managed to repro locally too - it looks like sls-plugin-ts uses .build to construct the zip and then copies it into .serverless, but it's still set on one of the properties we look at to get the zip path. I'm having a quick look now at how the AWS plugin does it since in my testing it seemed fine with that

@RichardDRJ
Copy link
Contributor

@revmischa I've pushed a change in #13 - would you be able to give it a go? It seems like our logic to pick up the deployment package wasn't correct for packages generated by sls-plugin-ts

@revmischa
Copy link
Contributor Author

Branch 'fix/not-picking-up-correct-package' set up to track remote branch 'fix/not-picking-up-correct-package' from 'up'.
Switched to a new branch 'fix/not-picking-up-correct-package'

❯ npm link

added 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
❯ npm i

added 97 packages, removed 6 packages, and audited 1021 packages in 4s

found 0 vulnerabilities
❯ npm run build

> [email protected] build
> tsc
❯ npm link serverless-aws-cdk

removed 201 packages, changed 1 package, and audited 1367 packages in 6s

46 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
❯ sls deploy
Serverless: Running "serverless" installed locally (in service node_modules)
^C
❯ sls deploy
Serverless: Running "serverless" installed locally (in service node_modules)
Serverless: DOTENV: Loading environment variables from .env.development:
Serverless:          - STAGE
Serverless:          - AWS_XRAY_CONTEXT_MISSING
Serverless:          - DB_HOST
Serverless:          - DB_NAME
Serverless: Configuration warning: Unrecognized provider 'aws-cdk'
Serverless:
Serverless: You're relying on provider plugin which doesn't provide a validation schema for its config.
Serverless: Please report the issue at its bug tracker linking: https://www.serverless.com/framework/docs/providers/aws/guide/plugins#extending-validation-schema
Serverless: You may turn off this message with "configValidationMode: off" setting
Serverless:
Serverless: Compiling with Typescript...
Serverless: Using local tsconfig.json
Serverless: Typescript compiled.
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Trusted accounts:
Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...

  Error --------------------------------------------------

  Error: Cannot find module '/Users/cyber/dev/jb/mercury/packages/backend/cdk'
  Require stack:
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/cdk/serverlessStack.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/cdk/app.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/cdk/toolkit.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/cdk/deployStack.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/deploy/awsCdkDeploy.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/deploy/index.js
  - /Users/cyber/dev/jb/serverless-aws-cdk/build/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
  - /usr/local/lib/node_modules/serverless/lib/Serverless.js
  - /usr/local/lib/node_modules/serverless/scripts/serverless.js
  - /usr/local/lib/node_modules/serverless/bin/serverless.js
      at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
      at Function.Module._load (internal/modules/cjs/loader.js:687:27)
      at Module.require (internal/modules/cjs/loader.js:849:19)
      at require (internal/modules/cjs/helpers.js:74:18)
      at new ServerlessStack (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/serverlessStack.ts:87:25)
      at Object.buildApp (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/app.ts:26:5)
      at AwsCdkProvider.synthesizer (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/toolkit.ts:15:17)
      at CloudExecutable.doSynthesize (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/aws-cdk/lib/api/cxapp/cloud-executable.ts:67:24)
      at CloudExecutable.synthesize (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/aws-cdk/lib/api/cxapp/cloud-executable.ts:53:29)
      at CdkToolkit.selectStacksForDeploy (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/aws-cdk/lib/cdk-toolkit.ts:380:22)
      at CdkToolkit.deploy (/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/aws-cdk/lib/cdk-toolkit.ts:111:20)
      at AwsCdkDeploy.deployStack (/Users/cyber/dev/jb/serverless-aws-cdk/cdk/deployStack.ts:8:3)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.13.0
     Framework Version:         2.5.0 (local)
     Plugin Version:            4.0.4
     SDK Version:               2.3.2
     Components Version:        3.2.1

❯ l
total 1256
drwxr-xr-x   17 cyber  staff   544B  8 Oct 20:10 .
drwxr-xr-x    6 cyber  staff   192B  8 Oct 18:23 ..
-rw-r--r--    1 cyber  staff   6.0K  8 Oct 18:23 .DS_Store
-rw-r--r--    1 cyber  staff   146B  8 Oct 18:23 .env.development
-rw-r--r--    1 cyber  staff    10B  8 Oct 18:18 .env.production
-rw-r--r--    1 cyber  staff   376B  8 Oct 18:18 .eslintrc.yml
-rw-r--r--    1 cyber  staff   134B  8 Oct 18:24 .gitignore
drwxr-xr-x    3 cyber  staff    96B  8 Oct 20:10 .serverless
drwxr-xr-x    3 cyber  staff    96B  8 Oct 20:10 .serverless-aws-cdk-assembly
drwxr-xr-x    4 cyber  staff   128B  8 Oct 18:42 build
drwxr-xr-x    4 cyber  staff   128B  8 Oct 18:23 cdk
drwxr-xr-x  793 cyber  staff    25K  8 Oct 20:08 node_modules
-rw-r--r--    1 cyber  staff   587K  8 Oct 20:08 package-lock.json
-rw-r--r--    1 cyber  staff   1.8K  8 Oct 20:08 package.json
-rw-r--r--    1 cyber  staff   1.5K  8 Oct 19:48 serverless.yml
drwxr-xr-x    6 cyber  staff   192B  8 Oct 18:45 src
-rw-r--r--    1 cyber  staff   5.4K  8 Oct 18:23 tsconfig.json
❯ ls cdk
database.ts index.ts

@revmischa
Copy link
Contributor Author

It says Cannot find module '/Users/cyber/dev/jb/mercury/packages/backend/cdk' but I do have that directory and index.ts inside

@revmischa
Copy link
Contributor Author

I do however have build/cdk - as my tsconfig outputDir is set to build/

❯ l build/cdk
total 48
drwxr-xr-x  8 cyber  staff   256B  8 Oct 18:42 .
drwxr-xr-x  4 cyber  staff   128B  8 Oct 18:42 ..
-rw-r--r--  1 cyber  staff   239B  8 Oct 19:41 database.d.ts
-rw-r--r--  1 cyber  staff   3.8K  8 Oct 19:41 database.js
-rw-r--r--  1 cyber  staff   2.5K  8 Oct 19:41 database.js.map
-rw-r--r--  1 cyber  staff   285B  8 Oct 19:41 index.d.ts
-rw-r--r--  1 cyber  staff   513B  8 Oct 19:41 index.js
-rw-r--r--  1 cyber  staff   347B  8 Oct 19:41 index.js.map

@revmischa
Copy link
Contributor Author

If I set cdkModulePath: ./build/cdk it gets farther. Now I'm back to

Trusted accounts:
Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...
cdk/index.ts(7,11): error TS2345: Argument of type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").Construct' is not assignable to parameter of type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").Construct'.
  Types of property 'node' are incompatible.
    Type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
      Types have separate declarations of a private property 'host'.
cdk/index.ts(9,24): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'Infrastructure' is not assignable to type 'Construct'.
    Types of property 'node' are incompatible.
      Type 'import("/Users/cyber/dev/jb/serverless-aws-cdk/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("/Users/cyber/dev/jb/mercury/packages/backend/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
        Types have separate declarations of a private property 'host'.

Maybe because I'm running a local version and not the npm module?

@RichardDRJ
Copy link
Contributor

RichardDRJ commented Oct 8, 2020

Yeah, that seems like it could be the issue. For testing locally, I've been doing the following from my service directory:

SERVERLESS_AWS_CDK_PATH=../serverless-aws-cdk
pushd ${SERVERLESS_AWS_CDK_PATH} && \
    npm i && npm run build && npm pack && popd && \
    rm -rf node_modules && npm i && npm install ${SERVERLESS_AWS_CDK_PATH}/serverless-aws-cdk-0.7.0.tgz

SLS_DEBUG=* npm run sls -- deploy -s dev

Not sure if that'll help in your case? If not, happy to publish another version with the function path fix tomorrow morning and see if that sorts it!

@revmischa
Copy link
Contributor Author

Yep that works! Thanks!

@revmischa
Copy link
Contributor Author

It does try to deploy to CF but errors:

Execution policies: arn:aws:iam::aws:policy/AdministratorAccess
Serverless: Compiling TypeScript infrastructure definition with config /Users/cyber/dev/jb/mercury/packages/backend/tsconfig.json...
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬────────────────────────────────────────────────────────────┬────────┬────────────────┬──────────────────────────────┬───────────┐
│   │ Resource                                                   │ Effect │ Action         │ Principal                    │ Condition │
├───┼────────────────────────────────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${sendTestSmsApi-ServerlessDeployedLambda/ServiceRole.Arn} │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
├───┼────────────────────────────────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${sendTestSms-ServerlessDeployedLambda/ServiceRole.Arn}    │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
├───┼────────────────────────────────────────────────────────────┼────────┼────────────────┼──────────────────────────────┼───────────┤
│ + │ ${testJson-ServerlessDeployedLambda/ServiceRole.Arn}       │ Allow  │ sts:AssumeRole │ Service:lambda.amazonaws.com │           │
└───┴────────────────────────────────────────────────────────────┴────────┴────────────────┴──────────────────────────────┴───────────┘
IAM Policy Changes
┌───┬────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────┐
│   │ Resource                                               │ Managed Policy ARN                                                             │
├───┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${sendTestSmsApi-ServerlessDeployedLambda/ServiceRole} │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
├───┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${sendTestSms-ServerlessDeployedLambda/ServiceRole}    │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
├───┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ + │ ${testJson-ServerlessDeployedLambda/ServiceRole}       │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole │
└───┴────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────┘
Security Group Changes
┌───┬─────────────────────────────────────────────────────────────────────┬─────┬────────────┬─────────────────┐
│   │ Group                                                               │ Dir │ Protocol   │ Peer            │
├───┼─────────────────────────────────────────────────────────────────────┼─────┼────────────┼─────────────────┤
│ + │ ${dev-mercury/AuroraSlsStack/MercuryAuroraDB/SecurityGroup.GroupId} │ Out │ Everything │ Everyone (IPv4) │
└───┴─────────────────────────────────────────────────────────────────────┴─────┴────────────┴─────────────────┘
(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
dev-mercury: deploying...
[0%] start: Publishing 22c70e670ec6a95e3179cfbfec4b10cfe3cbdecf379d4e0958ae7313f06c920f:current
[100%] success: Published 22c70e670ec6a95e3179cfbfec4b10cfe3cbdecf379d4e0958ae7313f06c920f:current
dev-mercury: creating CloudFormation changeset...
[█████▌····················································] (2/21)

9:01:12 PM | CREATE_FAILED        | AWS::Lambda::Function                 | sendTestSms-ServerlessDeployedLambda
mercury-dev-sendTestSms already exists in stack arn:aws:cloudformation:us-east-1:899001065887:stack/mercury-dev/f828fc40-087a-11eb-96fd-0eac0ccc6c9d
9:01:14 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack            | dev-mercury
The following resource(s) failed to create: [sendTestSmsServerlessDeployedLambdaBD20C2FD]. . Rollback requested by user.














 ❌  dev-mercury failed: Error: The stack named dev-mercury failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/api/util/cloudformation.ts:305:11)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.deployStack (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/api/deploy-stack.ts:283:26)
    at CdkToolkit.deploy (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
    at AwsCdkDeploy.deployStack (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless-aws-cdk/cdk/deployStack.ts:8:3)

  Error --------------------------------------------------

  Error: The stack named dev-mercury failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
      at Object.waitForStackDeploy (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/api/util/cloudformation.ts:305:11)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at Object.deployStack (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/api/deploy-stack.ts:283:26)
      at CdkToolkit.deploy (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
      at AwsCdkDeploy.deployStack (/Users/cyber/dev/jb/mercury/packages/backend/node_modules/serverless-aws-cdk/cdk/deployStack.ts:8:3)

Same result after doing sls remove first

@RichardDRJ
Copy link
Contributor

From that output (and from the serverless.yml in #8), it looks like you've set stackName to dev-mercury, but there's already a stack called mercury-dev with the resources you're trying to create. If mercury-dev is a stack created by a previous deploy before you set stackName, you could destroy the stack in the CloudFormation console. Otherwise, if you want to take ownership of that one you could set your stackName to mercury-dev and either build on top of it or sls remove it and then re-create dev-mercury?

@revmischa
Copy link
Contributor Author

Oh yeah, I used the config from the example stackName: '${self:provider.stage}-${self:service}'
I think it should be "${self:service}-${self:provider.stage}"
That fixed it! Finally deployed the stack

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

No branches or pull requests

2 participants