Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.Use CreateKeyGroup with an AWS SDK
The following code example shows how to use CreateKeyGroup.
- Java
-
- SDK for Java 2.x
-
A key group requires at least one public key that is used to verify signed URLs or cookies.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.cloudfront.CloudFrontClient;
import java.util.UUID;
public class CreateKeyGroup {
private static final Logger logger = LoggerFactory.getLogger(CreateKeyGroup.class);
public static String createKeyGroup(CloudFrontClient cloudFrontClient, String publicKeyId) {
String keyGroupId = cloudFrontClient.createKeyGroup(b -> b.keyGroupConfig(c -> c
.items(publicKeyId)
.name("JavaKeyGroup" + UUID.randomUUID())))
.keyGroup().id();
logger.info("KeyGroup created with ID: [{}]", keyGroupId);
return keyGroupId;
}
}
For a complete list of AWS SDK developer guides and code examples, see
Using CloudFront with an AWS SDK.
This topic also includes information about getting started and details about previous SDK versions.