Class DefaultIamPolicy.Builder

java.lang.Object
software.amazon.awssdk.policybuilder.iam.internal.DefaultIamPolicy.Builder
All Implemented Interfaces:
IamPolicy.Builder, Buildable, CopyableBuilder<IamPolicy.Builder,IamPolicy>, SdkBuilder<IamPolicy.Builder,IamPolicy>
Enclosing class:
DefaultIamPolicy

public static class DefaultIamPolicy.Builder extends Object implements IamPolicy.Builder
  • Method Details

    • id

      public IamPolicy.Builder id(String id)
      Description copied from interface: IamPolicy.Builder
      Configure the Id element of the policy, specifying an optional identifier for the policy.

      The ID is used differently in different services. ID is allowed in resource-based policies, but not in identity-based policies.

      For services that let you set an ID element, we recommend you use a UUID (GUID) for the value, or incorporate a UUID as part of the ID to ensure uniqueness.

      This value is optional.

       IamPolicy policy =
           IamPolicy.builder()
                    .id("cd3ad3d9-2776-4ef1-a904-4c229d1642ee") // An identifier for the policy
                    .addStatement(IamStatement.builder()
                                              .effect(IamEffect.DENY)
                                              .addAction(IamAction.ALL)
                                              .build())
                    .build();
      
      Specified by:
      id in interface IamPolicy.Builder
      See Also:
    • version

      public IamPolicy.Builder version(String version)
      Description copied from interface: IamPolicy.Builder
      Configure the Version element of the policy, specifying the language syntax rules that are to be used to process the policy.

      By default, this value is 2012-10-17.

      IamPolicy policy =
          IamPolicy.builder()
                   .version("2012-10-17") // The IAM policy language syntax version to use
                   .addStatement(IamStatement.builder()
                                             .effect(IamEffect.DENY)
                                             .addAction(IamAction.ALL)
                                             .build())
                   .build();
      
      Specified by:
      version in interface IamPolicy.Builder
      See Also:
    • statements

      public IamPolicy.Builder statements(Collection<IamStatement> statements)
      Description copied from interface: IamPolicy.Builder
      Configure the Statement element of the policy, specifying the access rules for this policy.

      This will replace any other statements already added to the policy. At least one statement is required to create a policy.

      IamPolicy policy =
          IamPolicy.builder()
                   // Add a statement to this policy that denies all actions:
                   .statements(Arrays.asList(IamStatement.builder()
                                                         .effect(IamEffect.DENY)
                                                         .addAction(IamAction.ALL)
                                                         .build()))
                   .build();
      
      Specified by:
      statements in interface IamPolicy.Builder
      See Also:
    • addStatement

      public IamPolicy.Builder addStatement(IamStatement statement)
      Description copied from interface: IamPolicy.Builder
      Append a Statement element to this policy to specify additional access rules.

      At least one statement is required to create a policy.

      IamPolicy policy =
          IamPolicy.builder()
                   // Add a statement to this policy that denies all actions:
                   .addStatement(IamStatement.builder()
                                             .effect(IamEffect.DENY)
                                             .addAction(IamAction.ALL)
                                             .build())
                   .build();
      
      Specified by:
      addStatement in interface IamPolicy.Builder
      See Also:
    • addStatement

      public IamPolicy.Builder addStatement(Consumer<IamStatement.Builder> statement)
      Description copied from interface: IamPolicy.Builder
      Append a Statement element to this policy to specify additional access rules.

      This works the same as IamPolicy.Builder.addStatement(IamStatement), except you do not need to specify IamStatement .builder() or build(). At least one statement is required to create a policy.

      IamPolicy policy =
          IamPolicy.builder()
                   // Add a statement to this policy that denies all actions:
                   .addStatement(s -> s.effect(IamEffect.DENY)
                                       .addAction(IamAction.ALL))
                   .build();
      
      Specified by:
      addStatement in interface IamPolicy.Builder
      See Also:
    • build

      public IamPolicy build()
      Description copied from interface: SdkBuilder
      An immutable object that is created from the properties that have been set on the builder.
      Specified by:
      build in interface Buildable
      Specified by:
      build in interface SdkBuilder<IamPolicy.Builder,IamPolicy>
      Returns:
      an instance of T