List of usage examples for com.amazonaws.services.s3 AmazonS3 setBucketPolicy
public void setBucketPolicy(String bucketName, String policyText) throws SdkClientException, AmazonServiceException;
Sets the policy associated with the specified bucket.
From source file:aws.example.s3.SetBucketPolicy.java
License:Open Source License
public static void setBucketPolicy(String bucket_name, String policy_text) { final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient(); try {/*from w ww.j a va 2s. c om*/ s3.setBucketPolicy(bucket_name, policy_text); } catch (AmazonServiceException e) { System.err.println(e.getErrorMessage()); System.exit(1); } }
From source file:jp.classmethod.aws.gradle.s3.BucketPolicyTask.java
License:Apache License
@TaskAction public void applyBucketPolicy() { // to enable conventionMappings feature String bucketName = getBucketName(); Policy policy = getPolicy();/*from ww w.j a v a2s .c om*/ if (bucketName == null) { throw new GradleException("bucketName is not specified"); } if (policy == null) { throw new GradleException("policy is not specified"); } AmazonS3PluginExtension ext = getProject().getExtensions().getByType(AmazonS3PluginExtension.class); AmazonS3 s3 = ext.getClient(); String policyJson = policy.toJson(); getLogger().info("Setting s3://{} bucket policy to {}", bucketName, policyJson); s3.setBucketPolicy(bucketName, policy.toJson()); }