Deployment Integrations

Setting up Java SDK with AWS CDK

AWS CDK
AWS CDK

AWS CDK

Step 1: Apply Configuration Changes to Your Function Properties

  • Add the thundra_apiKey environment variable along with your Thundra API key.

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.lambda.Function
public class YourConstructClass extends Construct {
String thundraApiKey = <your_api_key>;
public YourConstructClass(Construct scope, String id) {
Function function = Function.Builder.create(this, "YourFunction")
... // other function properties
.environment(new HashMap<String, String>() {{
... // other environment variables
put("thundra_apiKey", thundraApiKey);
}})
.build();
}
}
  • Define the Thundra layer and add it to your function properties.

Latest version of Thundra's Java layer:

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.lambda.Function
import software.amazon.awscdk.services.lambda.ILayerVersion;
import software.amazon.awscdk.services.lambda.LayerVersion;
public class YourConstructClass extends Construct {
String thundraApiKey = <your_api_key>;
String thundraAWSAccountNo = "269863060030";
String thundraJavaLayerVersion = "44"; // or any other version;
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
this,
null,
String.format(
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
)
);
public YourConstructClass(Construct scope, String id) {
Function function = Function.Builder.create(this, "YourFunction")
... // other function properties
.environment(new HashMap<String, String>() {{
... // other environment variables
put("thundra_apiKey", thundraApiKey);
}})
.layers(Arrays.asList(
thundraLayer,
... // other layers
))
.build();
}
}

Aws.REGION is a pseudo parameter which is bootstrapped from your stack's environment configuration.

  • 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 handler.

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.lambda.Function
import software.amazon.awscdk.services.lambda.ILayerVersion;
import software.amazon.awscdk.services.lambda.LayerVersion;
import software.amazon.awscdk.core.Aws;
public class YourConstructClass extends Construct {
String thundraApiKey = <your_api_key>;
String thundraAWSAccountNo = "269863060030";
String thundraJavaLayerVersion = "44"; // or any other version;
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
this,
null,
String.format(
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
)
);
public YourConstructClass(Construct scope, String id) {
Function function = Function.Builder.create(this, "MyFunction")
... // other function properties
.handler("io.thundra.agent.lambda.core.handler.ThundraLambdaHandler")
.environment(new HashMap<String, String>() {{
... // other environment variables
put("thundra_apiKey", thundraApiKey);
put("thundra_agent_lambda_handler", "yourdomain.yourpackage.yourhandler");
}})
.layers(Arrays.asList(
thundraLayer,
... // other layers
))
.build();
}
}

An example configuration:

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.services.lambda.Function
import software.amazon.awscdk.services.lambda.ILayerVersion;
import software.amazon.awscdk.services.lambda.LayerVersion;
import software.amazon.awscdk.services.lambda.Runtime;
import software.amazon.awscdk.core.Aws;
public class YourConstructClass extends Construct {
String thundraApiKey = "<your_api_key>";
String thundraAWSAccountNo = "269863060030";
String thundraJavaLayerVersion = "44" // or any other version;
ILayerVersion thundraLayer = LayerVersion.fromLayerVersionArn(
this,
null,
String.format(
"arn:aws:lambda:%s:%s:layer:thundra-lambda-java-layer:%s",
Aws.REGION, thundraAWSAccountNo, thundraJavaLayerVersion
)
);
public YourConstructClass(Construct scope, String id) {
Function function = Function.Builder.create(this, "YourFunction")
.runtime(Runtime.JAVA_8)
.code(Code.fromAsset("/path/to/your/function/package"))
.handler("io.thundra.agent.lambda.core.handler.ThundraLambdaHandler")
.environment(new HashMap<String, String>() {{
put("thundra_apiKey", thundraApiKey);
put("thundra_agent_lambda_handler", "yourdomain.yourpackage.yourhandler");
}})
.layers(Collections.singletonList(thundraLayer))
.build();
}
}

Step 2: Build and Deploy

mvn compile && cdk deploy

Step 3: Invoke Your Function

Now you can invoke your Lambda function and see the details of your invocation in the Thundra console!