Skip to content

Commit

Permalink
feat: add skeleton of step function class and example stack
Browse files Browse the repository at this point in the history
  • Loading branch information
lym953 committed Oct 16, 2024
1 parent 1fe6976 commit 7ed97a7
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/step-functions-typescript-stack/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
3 changes: 3 additions & 0 deletions examples/step-functions-typescript-stack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Datadog CDK TypeScript Example

This example is used to test the [datadog-cdk-constructs](https://github.com/DataDog/datadog-cdk-constructs) v2 library for Step Functions. The Step Functions support is still in development. Once it's ready, this example will be merged into the `typescript-stack` so that a single stack can be used for testing both Lambda functions and Step Functions, making it easier for CDK construct developers to test their changes. The two examples are kept separate for now so the incomplete Step Function support won't break the testing of Lambda functions.
7 changes: 7 additions & 0 deletions examples/step-functions-typescript-stack/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node
import * as cdk from "aws-cdk-lib";
import { CdkStepFunctionsTypeScriptStack } from "../lib/cdk-step-functions-typescript-stack";

const app = new cdk.App();
new CdkStepFunctionsTypeScriptStack(app, "CdkStepFunctionsTypeScriptStack", {});
app.synth();
39 changes: 39 additions & 0 deletions examples/step-functions-typescript-stack/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"app": "npx ts-node --prefer-ts-exts bin/index.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as sfn from "aws-cdk-lib/aws-stepfunctions";
import { Duration, Stack, StackProps } from "aws-cdk-lib";
import { Construct } from "constructs";
import { DatadogStepFunctions } from "datadog-cdk-constructs-v2";
import * as tasks from "aws-cdk-lib/aws-stepfunctions-tasks";

export class CdkStepFunctionsTypeScriptStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Creating Hello World TypeScript stack");

const helloLambdaFunction = new lambda.Function(this, "hello-python", {
runtime: lambda.Runtime.PYTHON_3_12,
timeout: Duration.seconds(10),
memorySize: 256,
code: lambda.Code.fromAsset("../lambda/python", {
bundling: {
image: lambda.Runtime.PYTHON_3_12.bundlingImage,
command: ["bash", "-c", "pip install -r requirements.txt -t /asset-output && cp -aT . /asset-output"],
},
}),
handler: "hello.lambda_handler",
});

const stateMachine = new sfn.StateMachine(this, "MyStateMachine", {
definitionBody: sfn.DefinitionBody.fromChainable(
new tasks.LambdaInvoke(this, "MyLambdaTask", {
lambdaFunction: helloLambdaFunction,
}).next(new sfn.Succeed(this, "GreetedWorld")),
),
});

console.log("Instrumenting Step Functions in TypeScript stack with Datadog");

const datadogSfn = new DatadogStepFunctions(this, "Datadog", {});
datadogSfn.addStateMachines([stateMachine]);
}
}
20 changes: 20 additions & 0 deletions examples/step-functions-typescript-stack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "typescript-stack",
"version": "1.0.0",
"bin": {
"cdk-typescript": "bin/index.js"
},
"devDependencies": {
"@types/node": "^20.8.8",
"aws-cdk": "^2.134.0",
"ts-node": "^10.9.1",
"typescript": "~5.2.2"
},
"dependencies": {
"@aws-cdk/aws-lambda-go-alpha": "^2.134.0-alpha.0",
"@aws-cdk/aws-lambda-python-alpha": "^2.134.0-alpha.0",
"aws-cdk-lib": "^2.134.0",
"constructs": "^10.3.0",
"datadog-cdk-constructs-v2": "^1.15.0"
}
}
23 changes: 23 additions & 0 deletions src/datadog-step-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed
* under the Apache License Version 2.0.
*
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2021 Datadog, Inc.
*/

import * as sfn from "aws-cdk-lib/aws-stepfunctions";
import { Construct } from "constructs";
import { DatadogStepFunctionsProps } from "./index";

export class DatadogStepFunctions extends Construct {
scope: Construct;
props: DatadogStepFunctionsProps;
constructor(scope: Construct, id: string, props: DatadogStepFunctionsProps) {
super(scope, id);
this.scope = scope;
this.props = props;
}

public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

export * from "./datadog";
export * from "./datadog-lambda";
export * from "./datadog-step-functions";
export * from "./layer";
export * from "./redirect";
export * from "./forwarder";
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ export interface Node {
}

export type LambdaFunction = lambda.Function | lambda.SingletonFunction;

export interface DatadogStepFunctionsProps {}

0 comments on commit 7ed97a7

Please sign in to comment.