Skip to content

Commit

Permalink
Further README update for getting properties
Browse files Browse the repository at this point in the history
This includes updates to the serverless types so you can directly pull
out the provider and call methods on it like `getAccountId();`.
  • Loading branch information
RichardDRJ committed Oct 9, 2020
1 parent 7c3d57a commit f78a270
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 12 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ provider:
cdkModulePath: ./cdk
region: 'eu-west-1'
stackName: '${self:provider.stage}-${self:service}'
cfnRole: 'arn:aws:iam::${self:custom.env.aws_account_id}:role/CfnRole'

package:
exclude:
Expand Down Expand Up @@ -289,6 +288,24 @@ After stack deployment, CDK by default prints out stack Outputs. We recommend us
new cdk.CfnOutput(this, 'HelloApiUrl', { value: hello.url }).overrideLogicalId('HelloApiUrl');
```

### Other Properties

Other properties are accessible through the AWS CDK provider. You can get an instance of it with:

``` typescript
import { AwsCdkProvider } from "serverless-aws-cdk/provider"

// And inside your stack definition...
const provider = props.serverless.getProvider("aws-cdk") as AwsCdkProvider;
```

From there, you can call [any method on the class](https://github.com/snap40/serverless-aws-cdk/blob/master/provider/awsCdkProvider.ts). For example:

``` typescript
const accountId = provider.getAccountId();
const region = provider.getRegion();
```

## Usage

### Supported Commands
Expand Down
4 changes: 2 additions & 2 deletions cdk/toolkitStack.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Serverless = require("serverless");
import serverless = require("../types/serverless");

import {Bootstrapper, ToolkitInfo} from "aws-cdk";
import {AwsCdkDeploy} from "../deploy";

function getToolkitStackName(serverless: Serverless) {
function getToolkitStackName(serverless: serverless) {
// DEFAULT_TOOLKIT_STACK_NAME from aws-cdk/deployment-target
const DEFAULT_TOOLKIT_STACK_NAME = "CDKToolkit";
return (
Expand Down
2 changes: 1 addition & 1 deletion compile/awsCdkCompile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BbPromise = require('bluebird');
import serverless = require('serverless');
import serverless = require("../types/serverless");
import { AwsCdkProvider } from '../provider';

import { compile, clean } from '../cdk/compile';
Expand Down
2 changes: 1 addition & 1 deletion deploy/awsCdkDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BbPromise = require("bluebird");
import serverless = require("serverless");
import serverless = require("../types/serverless");
import { AwsCdkProvider } from "../provider";

import { bootstrapToolkitStack } from "../cdk/toolkitStack";
Expand Down
2 changes: 1 addition & 1 deletion diff/awsCdkDiff.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BbPromise = require('bluebird');
import serverless = require('serverless');
import serverless = require("../types/serverless");
import { AwsCdkProvider } from '../provider';

import { diffStack } from '../cdk/diffStack';
Expand Down
2 changes: 1 addition & 1 deletion provider/awsCdkProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ = require("lodash");
import serverless = require("serverless");
import serverless = require("../types/serverless");
import {ISDK, SdkProvider, Mode} from "aws-cdk";
import path = require("path");
import cxapi = require("@aws-cdk/cx-api");
Expand Down
2 changes: 1 addition & 1 deletion remove/awsCdkRemove.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BbPromise = require('bluebird');
import serverless = require('serverless');
import serverless = require("../types/serverless");
import { AwsCdkProvider } from '../provider';

import { removeStack, dummyArtifactsBeforeRemoveStack } from '../cdk/removeStack';
Expand Down
4 changes: 0 additions & 4 deletions types/serverless.d.ts

This file was deleted.

2 changes: 2 additions & 0 deletions types/serverless.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Serverless = any;
export = Serverless;

0 comments on commit f78a270

Please sign in to comment.