Skip to content

Commit dfd5772

Browse files
authored
add datadog exampes (#602)
* add examples for datadog * rename cdk folder and add it to repo * fix config path * unused file
1 parent 92b4993 commit dfd5772

39 files changed

+16524
-0
lines changed

examples/datadog-zip/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cdk.out
2+
node_modules

examples/datadog-zip/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Datadog support for Lambda Web Adapter
2+
3+
This folder contains examples using Lambda Web Adapter and Datadog instrumentation in nodejs (expressjs) using a zipfile and layers instead of a container.
4+
5+
The examples use aws cdk to deploy and curl to test, so make sure they are installed.
6+
7+
# How to use
8+
9+
Instructions are for expressjs
10+
11+
## Install dependencies
12+
13+
Install aws cdk dependencies
14+
15+
```sh
16+
cd expressjs/cdk
17+
npm i
18+
cd -
19+
```
20+
21+
## Deploy and Run
22+
23+
Deploy with
24+
25+
```sh
26+
cd expressjs/cdk
27+
cdk deploy
28+
cd -
29+
```
30+
31+
After confirming the deployment, a log will show a public Lambda URL to invoke the endpoint with
32+
33+
```sh
34+
Outputs:
35+
lwa-stack.LambdaFunctionUrl = https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.us-east-1.on.aws/
36+
```
37+
38+
and the function can be invoked with (note the call_lwa at the end of the URL)
39+
40+
```sh
41+
curl https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.lambda-url.us-east-1.on.aws/call_lwa
42+
```
43+
44+
NB
45+
this deployment will create a publicly accessible URL link with no security restriction and usage limits! Make sure to run
46+
47+
```sh
48+
cd expressjs/cdk
49+
cdk destroy
50+
cd -
51+
```
52+
53+
after the example test is done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Welcome to your CDK TypeScript project
2+
3+
This is a blank project for CDK development with TypeScript.
4+
5+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
6+
7+
## Useful commands
8+
9+
* `npm run build` compile typescript to js
10+
* `npm run watch` watch for changes and compile
11+
* `npm run test` perform the jest unit tests
12+
* `npx cdk deploy` deploy this stack to your default AWS account/region
13+
* `npx cdk diff` compare deployed stack with current state
14+
* `npx cdk synth` emits the synthesized CloudFormation template
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { App, CfnOutput, Duration, Stack, StackProps } from "aws-cdk-lib";
2+
import * as lambda from "aws-cdk-lib/aws-lambda";
3+
4+
import { FunctionUrlAuthType, Code } from "aws-cdk-lib/aws-lambda";
5+
import * as path from "path";
6+
7+
const app = new App();
8+
9+
class LwaStack extends Stack {
10+
constructor(scope: App, id: string, props?: StackProps) {
11+
super(scope, id, props);
12+
13+
const lwa_lambda = new lambda.Function(this, id, {
14+
code: Code.fromAsset(path.join(__dirname, "../../lambda-asset/src")),
15+
runtime: lambda.Runtime.NODEJS_20_X,
16+
handler: "run.sh",
17+
functionName: id + "-lambda",
18+
timeout: Duration.seconds(9),
19+
});
20+
21+
const functionUrl = lwa_lambda.addFunctionUrl({
22+
authType: FunctionUrlAuthType.NONE,
23+
});
24+
25+
new CfnOutput(this, "LambdaFunctionUrl", {
26+
value: functionUrl.url,
27+
description: "The Lambda Function URL",
28+
});
29+
30+
lwa_lambda.addEnvironment(
31+
"AWS_LWA_LAMBDA_RUNTIME_API_PROXY",
32+
"127.0.0.1:9002",
33+
);
34+
35+
lwa_lambda.addEnvironment("DD_TRACE_PARTIAL_FLUSH_MIN_SPANS", "1");
36+
lwa_lambda.addEnvironment("DD_TRACE_PARTIAL_FLUSH_ENABLED", "false");
37+
lwa_lambda.addEnvironment("DD_API_KEY", process.env.DD_API_KEY || "");
38+
lwa_lambda.addEnvironment("DD_SERVICE", id);
39+
lwa_lambda.addEnvironment("AWS_LAMBDA_EXEC_WRAPPER", "/opt/bootstrap");
40+
41+
const lwa_lambda_layer = lambda.LayerVersion.fromLayerVersionArn(
42+
this,
43+
"lwa_lambda-layer",
44+
"arn:aws:lambda:us-east-1:753240598075:layer:LambdaAdapterLayerX86:25",
45+
);
46+
const dd_layer = lambda.LayerVersion.fromLayerVersionArn(
47+
this,
48+
"lwa_lambda-dd-layer",
49+
"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:77",
50+
);
51+
lwa_lambda.addLayers(lwa_lambda_layer, dd_layer);
52+
}
53+
}
54+
55+
new LwaStack(app, "lwa-stack", {});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"acknowledged-issue-numbers": [
3+
32775
4+
]
5+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts app/cdk.ts",
3+
"watch": {
4+
"include": ["**"],
5+
"exclude": [
6+
"README.md",
7+
"cdk*.json",
8+
"**/*.d.ts",
9+
"**/*.js",
10+
"tsconfig.json",
11+
"package*.json",
12+
"yarn.lock",
13+
"node_modules",
14+
"test"
15+
]
16+
},
17+
"context": {
18+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
19+
"@aws-cdk/core:checkSecretUsage": true,
20+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
21+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
22+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
23+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
24+
"@aws-cdk/aws-iam:minimizePolicies": true,
25+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
26+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
27+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
28+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
29+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
30+
"@aws-cdk/core:enablePartitionLiterals": true,
31+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
32+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
33+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
34+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
35+
"@aws-cdk/aws-route53-patters:useCertificate": true,
36+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
37+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
38+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
39+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
40+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
41+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
42+
"@aws-cdk/aws-redshift:columnId": true,
43+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
44+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
45+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
46+
"@aws-cdk/aws-kms:aliasNameRef": true,
47+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
48+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
49+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
50+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
51+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
52+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
53+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
54+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
55+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
56+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
57+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
58+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
59+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
60+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
61+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
62+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
63+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
64+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
65+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false,
66+
"@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions": true,
67+
"@aws-cdk/aws-ec2:ec2SumTImeoutEnabled": true,
68+
"@aws-cdk/aws-appsync:appSyncGraphQLAPIScopeLambdaPermission": true,
69+
"@aws-cdk/aws-rds:setCorrectValueForDatabaseInstanceReadReplicaInstanceResourceId": true,
70+
"@aws-cdk/core:cfnIncludeRejectComplexResourceUpdateCreatePolicyIntrinsics": true,
71+
"@aws-cdk/aws-lambda-nodejs:sdkV3ExcludeSmithyPackages": true
72+
}
73+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
}
8+
};

0 commit comments

Comments
 (0)