Thundra APM
Search…
Deployment Integrations
Setting up Java SDK with AWS CDK
AWS CDK

Step 1: Add Thundra API Key

Add the THUNDRA_APIKEY environment variable along with your Thundra API key.
1
import software.amazon.awscdk.core.Construct;
2
import software.amazon.awscdk.services.lambda.Function
3
4
public class YourConstructClass extends Construct {
5
6
String thundraApiKey = <YOUR THUNDRA API KEY>;
7
8
public YourConstructClass(Construct scope, String id) {
9
10
Function function = Function.Builder.create(this, "YourFunction")
11
... // other function properties
12
.environment(new HashMap<String, String>() {{
13
... // other environment variables
14
put("THUNDRA_APIKEY", thundraApiKey);
15
}})
16
.build();
17
}
18
19
}
Copied!

Step 2: Add Thundra Layer

Define the Thundra layer and add it to your function properties.
Latest version of Thundra's Java layer:
1
import software.amazon.awscdk.core.Construct;
2
import software.amazon.awscdk.services.lambda.Function
3
import software.amazon.awscdk.services.lambda.ILayerVersion;
4
import software.amazon.awscdk.services.lambda.LayerVersion;
5
6
public class YourConstructClass extends Construct {
7
8
String thundraApiKey = <YOUR THUNDRA API KEY>;
9
String thundraAWSAccountNo = "269863060030";
10
String thundraJavaLayerVersion = "65"; // or any other version;
11
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
12
this,
13
null,
14
String.format(
15
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
16
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
17
)
18
);
19
20
public YourConstructClass(Construct scope, String id) {
21
Function function = Function.Builder.create(this, "YourFunction")
22
... // other function properties
23
.environment(new HashMap<String, String>() {{
24
... // other environment variables
25
put("THUNDRA_APIKEY", thundraApiKey);
26
}})
27
.layers(Arrays.asList(
28
thundraLayer,
29
... // other layers
30
))
31
.build();
32
}
33
34
}
Copied!
Aws.REGION is a pseudo parameter which is bootstrapped from your stack's environment configuration.

Step 3: Switch Handler

Change the handler of functions to be wrapped to io.thundra.agent.lambda.core.handler.ThundraLambdaHandler
and add the THUNDRA_AGENT_LAMBDA_HANDLER environment variable with your original handler.
1
import software.amazon.awscdk.core.Construct;
2
import software.amazon.awscdk.services.lambda.Function
3
import software.amazon.awscdk.services.lambda.ILayerVersion;
4
import software.amazon.awscdk.services.lambda.LayerVersion;
5
import software.amazon.awscdk.core.Aws;
6
7
public class YourConstructClass extends Construct {
8
9
String thundraApiKey = <YOUR THUNDRA API KEY>;
10
String thundraAWSAccountNo = "269863060030";
11
String thundraJavaLayerVersion = "65"; // or any other version;
12
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
13
this,
14
null,
15
String.format(
16
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
17
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
18
)
19
);
20
21
public YourConstructClass(Construct scope, String id) {
22
Function function = Function.Builder.create(this, "MyFunction")
23
... // other function properties
24
.handler("io.thundra.agent.lambda.core.handler.ThundraLambdaHandler")
25
.environment(new HashMap<String, String>() {{
26
... // other environment variables
27
put("THUNDRA_APIKEY", thundraApiKey);
28
put("THUNDRA_AGENT_LAMBDA_HANDLER", "yourdomain.yourpackage.yourhandler");
29
}})
30
.layers(Arrays.asList(
31
thundraLayer,
32
... // other layers
33
))
34
.build();
35
}
36
37
}
Copied!
An example configuration:
1
import software.amazon.awscdk.core.Construct;
2
import software.amazon.awscdk.services.lambda.Function
3
import software.amazon.awscdk.services.lambda.ILayerVersion;
4
import software.amazon.awscdk.services.lambda.LayerVersion;
5
import software.amazon.awscdk.services.lambda.Runtime;
6
import software.amazon.awscdk.core.Aws;
7
8
public class YourConstructClass extends Construct {
9
10
String thundraApiKey = "<YOUR THUNDRA API KEY>";
11
String thundraAWSAccountNo = "269863060030";
12
String thundraJavaLayerVersion = "65" // or any other version;
13
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
14
this,
15
null,
16
String.format(
17
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
18
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
19
)
20
);
21
22
public YourConstructClass(Construct scope, String id) {
23
Function function = Function.Builder.create(this, "YourFunction")
24
.runtime(Runtime.JAVA_8)
25
.code(Code.fromAsset("/path/to/your/function/package"))
26
.handler("io.thundra.agent.lambda.core.handler.ThundraLambdaHandler")
27
.environment(new HashMap<String, String>() {{
28
put("THUNDRA_APIKEY", thundraApiKey);
29
put("THUNDRA_AGENT_LAMBDA_HANDLER", "yourdomain.yourpackage.yourhandler");
30
}})
31
.layers(Collections.singletonList(thundraLayer))
32
.build();
33
}
34
35
}
Copied!
Copy link