AccessPointPolicy class

Provides a resource to manage an S3 Access Point resource policy.

> NOTE on Access Points and Access Point Policies: The provider provides both a standalone Access Point Policy resource and an Access Point resource with a resource policy defined in-line. You cannot use an Access Point with in-line resource policy in conjunction with an Access Point Policy resource. Doing so will cause a conflict of policies and will overwrite the access point's resource policy.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.s3.Bucket("example", {bucket: "example"});
const exampleAccessPoint = new aws.s3.AccessPoint("example", {
    publicAccessBlockConfiguration: {
        blockPublicAcls: true,
        blockPublicPolicy: false,
        ignorePublicAcls: true,
        restrictPublicBuckets: false,
    },
    bucket: example.id,
    name: "example",
}, {
    ignoreChanges: ["policy"],
});
const exampleAccessPointPolicy = new aws.s3control.AccessPointPolicy("example", {
    accessPointArn: exampleAccessPoint.arn,
    policy: pulumi.jsonStringify({
        Version: "2008-10-17",
        Statement: [{
            Effect: "Allow",
            Action: "s3:GetObjectTagging",
            Principal: {
                AWS: "*",
            },
            Resource: pulumi.interpolate`${exampleAccessPoint.arn}/object/*`,
        }],
    }),
});
import pulumi
import json
import pulumi_aws as aws

example = aws.s3.Bucket("example", bucket="example")
example_access_point = aws.s3.AccessPoint("example",
    public_access_block_configuration={
        "block_public_acls": True,
        "block_public_policy": False,
        "ignore_public_acls": True,
        "restrict_public_buckets": False,
    },
    bucket=example.id,
    name="example",
    opts = pulumi.ResourceOptions(ignore_changes=["policy"]))
example_access_point_policy = aws.s3control.AccessPointPolicy("example",
    access_point_arn=example_access_point.arn,
    policy=pulumi.Output.json_dumps({
        "Version": "2008-10-17",
        "Statement": [{
            "Effect": "Allow",
            "Action": "s3:GetObjectTagging",
            "Principal": {
                "AWS": "*",
            },
            "Resource": example_access_point.arn.apply(lambda arn: f"{arn}/object/*"),
        }],
    }))
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.S3.Bucket("example", new()
    {
        BucketName = "example",
    });

    var exampleAccessPoint = new Aws.S3.AccessPoint("example", new()
    {
        PublicAccessBlockConfiguration = new Aws.S3.Inputs.AccessPointPublicAccessBlockConfigurationArgs
        {
            BlockPublicAcls = true,
            BlockPublicPolicy = false,
            IgnorePublicAcls = true,
            RestrictPublicBuckets = false,
        },
        Bucket = example.Id,
        Name = "example",
    }, new CustomResourceOptions
    {
        IgnoreChanges =
        {
            "policy",
        },
    });

    var exampleAccessPointPolicy = new Aws.S3Control.AccessPointPolicy("example", new()
    {
        AccessPointArn = exampleAccessPoint.Arn,
        Policy = Output.JsonSerialize(Output.Create(new Dictionary<string, object?>
        {
            ["Version"] = "2008-10-17",
            ["Statement"] = new[]
            {
                new Dictionary<string, object?>
                {
                    ["Effect"] = "Allow",
                    ["Action"] = "s3:GetObjectTagging",
                    ["Principal"] = new Dictionary<string, object?>
                    {
                        ["AWS"] = "*",
                    },
                    ["Resource"] = exampleAccessPoint.Arn.Apply(arn => $"{arn}/object/*"),
                },
            },
        })),
    });

});
package main

import (
	"encoding/json"
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/s3"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/s3control"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := s3.NewBucket(ctx, "example", &s3.BucketArgs{
			Bucket: pulumi.String("example"),
		})
		if err != nil {
			return err
		}
		exampleAccessPoint, err := s3.NewAccessPoint(ctx, "example", &s3.AccessPointArgs{
			PublicAccessBlockConfiguration: &s3.AccessPointPublicAccessBlockConfigurationArgs{
				BlockPublicAcls:       pulumi.Bool(true),
				BlockPublicPolicy:     pulumi.Bool(false),
				IgnorePublicAcls:      pulumi.Bool(true),
				RestrictPublicBuckets: pulumi.Bool(false),
			},
			Bucket: example.ID().ToIDOutput().ToStringOutput(),
			Name:   pulumi.String("example"),
		}, pulumi.IgnoreChanges([]string{
			"policy",
		}))
		if err != nil {
			return err
		}
		_, err = s3control.NewAccessPointPolicy(ctx, "example", &s3control.AccessPointPolicyArgs{
			AccessPointArn: exampleAccessPoint.Arn,
			Policy: exampleAccessPoint.Arn.ApplyT(func(arn string) (pulumi.String, error) {
				var _zero pulumi.String
				tmpJSON0, err := json.Marshal(map[string]interface{}{
					"Version": "2008-10-17",
					"Statement": []map[string]interface{}{
						map[string]interface{}{
							"Effect": "Allow",
							"Action": "s3:GetObjectTagging",
							"Principal": map[string]string{
								"AWS": "*",
							},
							"Resource": fmt.Sprintf("%v/object/*", arn),
						},
					},
				})
				if err != nil {
					return _zero, err
				}
				json0 := string(tmpJSON0)
				return pulumi.String(json0), nil
			}).(pulumi.StringOutput),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

resource "aws_s3_bucket" "example" {
  bucket = "example"
}
resource "aws_s3_accesspoint" "example" {
  lifecycle {
    ignore_changes = [policy]
  }
  public_access_block_configuration = {
    block_public_acls       = true
    block_public_policy     = false
    ignore_public_acls      = true
    restrict_public_buckets = false
  }
  bucket = aws_s3_bucket.example.id
  name   = "example"
}
resource "aws_s3control_accesspointpolicy" "example" {
  access_point_arn = aws_s3_accesspoint.example.arn
  policy = jsonencode({
    "Version" = "2008-10-17"
    "Statement" = [{
      "Effect" = "Allow"
      "Action" = "s3:GetObjectTagging"
      "Principal" = {
        "AWS" = "*"
      }
      "Resource" ="${aws_s3_accesspoint.example.arn}/object/*"
    }]
  })
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.s3.Bucket;
import com.pulumi.aws.s3.BucketArgs;
import com.pulumi.aws.s3.AccessPoint;
import com.pulumi.aws.s3.AccessPointArgs;
import com.pulumi.aws.s3.inputs.AccessPointPublicAccessBlockConfigurationArgs;
import com.pulumi.aws.s3control.AccessPointPolicy;
import com.pulumi.aws.s3control.AccessPointPolicyArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var example = new Bucket("example", BucketArgs.builder()
            .bucket("example")
            .build());

        var exampleAccessPoint = new AccessPoint("exampleAccessPoint", AccessPointArgs.builder()
            .publicAccessBlockConfiguration(AccessPointPublicAccessBlockConfigurationArgs.builder()
                .blockPublicAcls(true)
                .blockPublicPolicy(false)
                .ignorePublicAcls(true)
                .restrictPublicBuckets(false)
                .build())
            .bucket(example.id())
            .name("example")
            .build(), CustomResourceOptions.builder()
                .ignoreChanges("policy")
                .build());

        var exampleAccessPointPolicy = new AccessPointPolicy("exampleAccessPointPolicy", AccessPointPolicyArgs.builder()
            .accessPointArn(exampleAccessPoint.arn())
            .policy(exampleAccessPoint.arn().applyValue(_arn -> serializeJson(
                jsonObject(
                    jsonProperty("Version", "2008-10-17"),
                    jsonProperty("Statement", jsonArray(jsonObject(
                        jsonProperty("Effect", "Allow"),
                        jsonProperty("Action", "s3:GetObjectTagging"),
                        jsonProperty("Principal", jsonObject(
                            jsonProperty("AWS", "*")
                        )),
                        jsonProperty("Resource", String.format("%s/object/*", _arn))
                    )))
                ))))
            .build());

    }
}
resources:
  example:
    type: aws:s3:Bucket
    properties:
      bucket: example
  exampleAccessPoint:
    type: aws:s3:AccessPoint
    name: example
    properties:
      publicAccessBlockConfiguration:
        blockPublicAcls: true
        blockPublicPolicy: false
        ignorePublicAcls: true
        restrictPublicBuckets: false
      bucket: ${example.id}
      name: example
    options:
      ignoreChanges:
        - policy
  exampleAccessPointPolicy:
    type: aws:s3control:AccessPointPolicy
    name: example
    properties:
      accessPointArn: ${exampleAccessPoint.arn}
      policy:
        fn::toJSON:
          Version: 2008-10-17
          Statement:
            - Effect: Allow
              Action: s3:GetObjectTagging
              Principal:
                AWS: '*'
              Resource: ${exampleAccessPoint.arn}/object/*

Import

Using pulumi import, import Access Point policies using the accessPointArn. For example:

$ pulumi import aws:s3control/accessPointPolicy:AccessPointPolicy example arn:aws:s3:us-west-2:123456789012:accesspoint/example

Constructors

AccessPointPolicy(String name, {AccessPointPolicyArgs? args, CustomResourceOptions? options})
Creates a new AccessPointPolicy. name The Pulumi resource name. args Arguments used to configure this AccessPointPolicy. The set of arguments for AccessPointPolicy. options Resource options controlling this resource's behavior.
AccessPointPolicy.reference(String urn)
Creates a typed reference to an existing AccessPointPolicy resource.

Properties

accessPointArn ↔ Output<String>
ARN of the access point that you want to associate with the specified policy.
latefinal
childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
hashCode → int
The hash code for this object.
no setterinherited
hasPublicAccessPolicy ↔ Output<bool>
Whether this access point currently has a policy that allows public access.
latefinal
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
policy ↔ Output<String>
Policy that you want to apply to the specified access point.
latefinal
region ↔ Output<String>
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {AccessPointPolicyState? state, CustomResourceOptions? options}) → AccessPointPolicy
Gets an existing AccessPointPolicy resource's state with the given name and id.