Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use CreateKeyGroup
with an Amazon SDK or CLI
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 Amazon SDK developer guides and code examples, see
Using CloudFront with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.