Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Hapus sumber CloudFront penandatanganan menggunakan AWS SDK
Contoh kode berikut menunjukkan cara menghapus sumber daya yang digunakan untuk mendapatkan akses ke konten terbatas di bucket Amazon Simple Storage Service (Amazon S3).
- Java
-
- SDKuntuk Java 2.x
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.cloudfront.CloudFrontClient;
import software.amazon.awssdk.services.cloudfront.model.DeleteKeyGroupResponse;
import software.amazon.awssdk.services.cloudfront.model.DeleteOriginAccessControlResponse;
import software.amazon.awssdk.services.cloudfront.model.DeletePublicKeyResponse;
import software.amazon.awssdk.services.cloudfront.model.GetKeyGroupResponse;
import software.amazon.awssdk.services.cloudfront.model.GetOriginAccessControlResponse;
import software.amazon.awssdk.services.cloudfront.model.GetPublicKeyResponse;
public class DeleteSigningResources {
private static final Logger logger = LoggerFactory.getLogger(DeleteSigningResources.class);
public static void deleteOriginAccessControl(final CloudFrontClient cloudFrontClient,
final String originAccessControlId) {
GetOriginAccessControlResponse getResponse = cloudFrontClient
.getOriginAccessControl(b -> b.id(originAccessControlId));
DeleteOriginAccessControlResponse deleteResponse = cloudFrontClient.deleteOriginAccessControl(builder -> builder
.id(originAccessControlId)
.ifMatch(getResponse.eTag()));
if (deleteResponse.sdkHttpResponse().isSuccessful()) {
logger.info("Successfully deleted Origin Access Control [{}]", originAccessControlId);
}
}
public static void deleteKeyGroup(final CloudFrontClient cloudFrontClient, final String keyGroupId) {
GetKeyGroupResponse getResponse = cloudFrontClient.getKeyGroup(b -> b.id(keyGroupId));
DeleteKeyGroupResponse deleteResponse = cloudFrontClient.deleteKeyGroup(builder -> builder
.id(keyGroupId)
.ifMatch(getResponse.eTag()));
if (deleteResponse.sdkHttpResponse().isSuccessful()) {
logger.info("Successfully deleted Key Group [{}]", keyGroupId);
}
}
public static void deletePublicKey(final CloudFrontClient cloudFrontClient, final String publicKeyId) {
GetPublicKeyResponse getResponse = cloudFrontClient.getPublicKey(b -> b.id(publicKeyId));
DeletePublicKeyResponse deleteResponse = cloudFrontClient.deletePublicKey(builder -> builder
.id(publicKeyId)
.ifMatch(getResponse.eTag()));
if (deleteResponse.sdkHttpResponse().isSuccessful()) {
logger.info("Successfully deleted Public Key [{}]", publicKeyId);
}
}
}
Untuk daftar lengkap panduan AWS SDK pengembang dan contoh kode, lihatMenggunakan CloudFront dengan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang SDK versi sebelumnya.