-
Notifications
You must be signed in to change notification settings - Fork 28
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
chore: Refactor example typescript stack by extracting a base class #300
Conversation
const helloPython = new 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", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const helloDotnet = new Function(this, "hello-dotnet", { | ||
runtime: lambda.Runtime.DOTNET_8, | ||
handler: "HelloWorld::HelloWorld.Handler::SayHi", | ||
memorySize: 256, | ||
code: lambda.Code.fromAsset("../lambda/dotnet/", { | ||
bundling: { | ||
image: lambda.Runtime.DOTNET_8.bundlingImage, | ||
command: [ | ||
"/bin/sh", | ||
"-c", | ||
" dotnet tool install -g Amazon.Lambda.Tools" + | ||
" && dotnet build" + | ||
" && dotnet lambda package --output-package /asset-output/function.zip", | ||
], | ||
user: "root", | ||
outputType: BundlingOutput.ARCHIVED, | ||
}, | ||
}), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const helloNode = new Function(this, "hello-node", { | ||
runtime: lambda.Runtime.NODEJS_20_X, | ||
memorySize: 256, | ||
timeout: Duration.seconds(10), | ||
code: lambda.Code.fromAsset("../lambda/node", { | ||
bundling: { | ||
image: lambda.Runtime.NODEJS_20_X.bundlingImage, | ||
command: ["bash", "-c", "cp -aT . /asset-output && npm install --prefix /asset-output"], | ||
user: "root", | ||
}, | ||
}), | ||
handler: "hello.lambda_handler", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const helloPython = new 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", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const helloDotnet = new Function(this, "hello-dotnet", { | ||
runtime: lambda.Runtime.DOTNET_8, | ||
handler: "HelloWorld::HelloWorld.Handler::SayHi", | ||
memorySize: 256, | ||
code: lambda.Code.fromAsset("../lambda/dotnet/", { | ||
bundling: { | ||
image: lambda.Runtime.DOTNET_8.bundlingImage, | ||
command: [ | ||
"/bin/sh", | ||
"-c", | ||
" dotnet tool install -g Amazon.Lambda.Tools" + | ||
" && dotnet build" + | ||
" && dotnet lambda package --output-package /asset-output/function.zip", | ||
], | ||
user: "root", | ||
outputType: BundlingOutput.ARCHIVED, | ||
}, | ||
}), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const helloNode = new Function(this, "hello-node", { | ||
runtime: lambda.Runtime.NODEJS_20_X, | ||
memorySize: 256, | ||
timeout: Duration.seconds(10), | ||
code: lambda.Code.fromAsset("../lambda/node", { | ||
bundling: { | ||
image: lambda.Runtime.NODEJS_20_X.bundlingImage, | ||
command: ["bash", "-c", "cp -aT . /asset-output && npm install --prefix /asset-output"], | ||
user: "root", | ||
}, | ||
}), | ||
handler: "hello.lambda_handler", | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Instrumenting Lambda Functions in TypeScript stack with Datadog"); | ||
|
||
const datadogLambda = new DatadogLambda(this, "Datadog", { | ||
const datadogProps: DatadogProps = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a separate variable to ensure DatadogProps
can be imported properly.
}); | ||
}; | ||
|
||
const datadogLambda = new Datadog(this, "Datadog", datadogProps); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just double checking, the change from DatadogLambda
to Datadog
was intended in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Yes it's intended. A PR for renaming the interfaces was reverted, so I want to change the example stack back to use all the old interfaces. Let me also rename the variable datadogLambda
to datadog
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that sounds good
cc428d7
to
d4e5aa1
Compare
/merge |
🚂 MergeQueue: pull request added to the queue The median merge time in Use |
What does this PR do?
Right now
This PR adds a class
CdkTypeScriptStackBase
, and makes:and
CdkTypeScriptStackBase
contains the setup of AWS resources, not related to Datadog.CdkTypeScriptStack
contains Datadog instrumentation code.Motivation
I'm going to rename the interfaces like I did in #288. To make sure both the new API and old API work, I will need to to write two stacks for testing the two APIs. The two stacks will share the non-Datadog setup code, so I'm putting this part in the base class.
Testing Guidelines
cdk deploy
successfully deploys the TypeScript stack.Additional Notes
Types of Changes
Check all that apply