Skip to content

Commit

Permalink
chore: clean up the code, add inline docs (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
misterjoshua authored Feb 16, 2022
1 parent 4001cb9 commit 6acd90c
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 277 deletions.
8 changes: 4 additions & 4 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const deployTask = project.addTask('integ:exec:deploy');
deployTask.exec(`rm -fr ${appDir}`);
deployTask.exec(`cdk --app "${tsNode} test/exec.integ.ts" deploy --output ${appDir}`);

const cliCmd = `${tsNode} src/cli/cdk-exec.ts --app ${appDir} exec`;
const cliCmd = `${tsNode} src/cli/cdk-exec.ts --app ${appDir}`;
project.addTask('integ:exec:sfn:succeed', {
exec: `${cliCmd} integ-cdk-exec/StateMachine --input '{"succeed":true}'`,
});
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

Provides `cdk-exec`, a command to tighten up your AWS CDK development loop by
helping you find and execute the physical resources for your lambdas and state
machines, with or without input. Example: `cdk-exec my-stack/MyLambda`
machines, with or without input.

```
$ cdk-exec integ-cdk-exec/Function --input '{"succeed":true}'
✨ Executing integ-cdk-exec-Function76856677-k5ehIzbG2T6S
Output:
{
"succeed": true,
"message": "Hello from Lambda"
}
✅ Execution succeeded
```

> WARNING: Do not rely on this tool to execute your functions in a production
> environment. Now that you have been warned, please read on.
Expand Down Expand Up @@ -64,7 +77,7 @@ $ cdk synth --output cdk.out

```
$ cdk-exec integ-cdk-exec/StateMachine --input '{"succeed":true}'
✨ Executing arn:aws:states:REGION:0000000000:stateMachine:StateMachine2E01A3A5-kPnq1OgV5KYX
✨ Executing arn:aws:states:REGION:000000000000:stateMachine:StateMachine2E01A3A5-8z4XHXAvT3qq
Output:
{
Expand All @@ -78,7 +91,7 @@ Output:

```
$ cdk-exec integ-cdk-exec/Function --input '{"succeed":true}'
✨ Executing arn:aws:states:REGION:0000000000:stateMachine:StateMachine2E01A3A5-kPnq1OgV5KYX
✨ Executing integ-cdk-exec-Function76856677-k5ehIzbG2T6S
Output:
{
Expand All @@ -93,7 +106,7 @@ Output:

```
$ cdk-exec --app path/to/cdkout integ-cdk-exec/Function --input '{"json":"here"}'
✨ Executing arn:aws:states:REGION:0000000000:stateMachine:StateMachine2E01A3A5-kPnq1OgV5KYX
✨ Executing integ-cdk-exec-Function76856677-k5ehIzbG2T6S
Output:
{
Expand Down
17 changes: 17 additions & 0 deletions src/aws-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import AWS from 'aws-sdk';

export interface IAwsSdk {
/**
* Get the CloudFormation client.
*/
cloudFormation(): AWS.CloudFormation;

/**
* Get the StepFunctions SDK client.
*/
stepFunctions(): AWS.StepFunctions;

/**
* Get the Lambda SDK client.
*/
lambda(): AWS.Lambda;
}

/**
* Creates AWS SDK clients.
*/
export class AwsSdk implements IAwsSdk {
cloudFormation(): AWS.CloudFormation {
return new AWS.CloudFormation();
Expand All @@ -18,6 +32,9 @@ export class AwsSdk implements IAwsSdk {
}
}

/**
* List stack resources.
*/
export class LazyListStackResources {
private readonly stackName: string;
private readonly cloudFormation: AWS.CloudFormation;
Expand Down
25 changes: 18 additions & 7 deletions src/cli/cdk-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as cxapi from 'aws-cdk-lib/cx-api';
import chalk from 'chalk';
import * as yargs from 'yargs';
import { AwsSdk } from '../aws-sdk';
import { AmbiguousPathError, getExecutor } from '../executor';
import { AmbiguousPathError, Executor } from '../executor';

async function main(): Promise<number> {
const args: any = yargs
Expand All @@ -29,20 +29,31 @@ async function main(): Promise<number> {
});
}

export interface ExecCmdOptions {
export interface CdkExecOptions {
/**
* App directory.
*/
readonly app: string;
readonly constructPath: string;

/**
* Path of the construct to execute.
*/
readonly constructPath?: string;

/**
* Execution input.
*/
readonly input?: string;
}

export async function cdkExec(options: ExecCmdOptions): Promise<number> {
export async function cdkExec(options: CdkExecOptions): Promise<number> {
const assembly = new cxapi.CloudAssembly(options.app);

try {
const executor = await getExecutor({
sdk: new AwsSdk(),
constructPath: options.constructPath,
const executor = await Executor.find({
assembly,
constructPath: options.constructPath,
sdk: new AwsSdk(),
});

if (!executor) {
Expand Down
Loading

0 comments on commit 6acd90c

Please sign in to comment.