AWS Classic

v4.30.0 published on Tuesday, Nov 30, 2021 by Pulumi

OriginAccessIdentity

Creates an Amazon CloudFront origin access identity.

For information about CloudFront distributions, see the Amazon CloudFront Developer Guide. For more information on generating origin access identities, see Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content.

Using With CloudFront

Normally, when referencing an origin access identity in CloudFront, you need to prefix the ID with the origin-access-identity/cloudfront/ special path. The cloudfront_access_identity_path allows this to be circumvented. The below snippet demonstrates use with the s3_origin_config structure for the aws.cloudfront.Distribution resource:

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

// ... other configuration ...
const example = new aws.cloudfront.Distribution("example", {origins: [{
    s3OriginConfig: {
        originAccessIdentity: aws_cloudfront_origin_access_identity.example.cloudfront_access_identity_path,
    },
}]});
import pulumi
import pulumi_aws as aws

# ... other configuration ...
example = aws.cloudfront.Distribution("example", origins=[aws.cloudfront.DistributionOriginArgs(
    s3_origin_config=aws.cloudfront.DistributionOriginS3OriginConfigArgs(
        origin_access_identity=aws_cloudfront_origin_access_identity["example"]["cloudfront_access_identity_path"],
    ),
)])
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        // ... other configuration ...
        var example = new Aws.CloudFront.Distribution("example", new Aws.CloudFront.DistributionArgs
        {
            Origins = 
            {
                new Aws.CloudFront.Inputs.DistributionOriginArgs
                {
                    S3OriginConfig = new Aws.CloudFront.Inputs.DistributionOriginS3OriginConfigArgs
                    {
                        OriginAccessIdentity = aws_cloudfront_origin_access_identity.Example.Cloudfront_access_identity_path,
                    },
                },
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudfront"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudfront.NewDistribution(ctx, "example", &cloudfront.DistributionArgs{
			Origins: cloudfront.DistributionOriginArray{
				&cloudfront.DistributionOriginArgs{
					S3OriginConfig: &cloudfront.DistributionOriginS3OriginConfigArgs{
						OriginAccessIdentity: pulumi.Any(aws_cloudfront_origin_access_identity.Example.Cloudfront_access_identity_path),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Updating your bucket policy

Note that the AWS API may translate the s3_canonical_user_id CanonicalUser principal into an AWS IAM ARN principal when supplied in an aws.s3.Bucket bucket policy, causing spurious diffs. If you see this behaviour, use the iam_arn instead:

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

const s3Policy = aws.iam.getPolicyDocument({
    statements: [{
        actions: ["s3:GetObject"],
        resources: [`${aws_s3_bucket.example.arn}/*`],
        principals: [{
            type: "AWS",
            identifiers: [aws_cloudfront_origin_access_identity.example.iam_arn],
        }],
    }],
});
const example = new aws.s3.BucketPolicy("example", {
    bucket: aws_s3_bucket.example.id,
    policy: s3Policy.then(s3Policy => s3Policy.json),
});
import pulumi
import pulumi_aws as aws

s3_policy = aws.iam.get_policy_document(statements=[aws.iam.GetPolicyDocumentStatementArgs(
    actions=["s3:GetObject"],
    resources=[f"{aws_s3_bucket['example']['arn']}/*"],
    principals=[aws.iam.GetPolicyDocumentStatementPrincipalArgs(
        type="AWS",
        identifiers=[aws_cloudfront_origin_access_identity["example"]["iam_arn"]],
    )],
)])
example = aws.s3.BucketPolicy("example",
    bucket=aws_s3_bucket["example"]["id"],
    policy=s3_policy.json)
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var s3Policy = Output.Create(Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
        {
            Statements = 
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
                {
                    Actions = 
                    {
                        "s3:GetObject",
                    },
                    Resources = 
                    {
                        $"{aws_s3_bucket.Example.Arn}/*",
                    },
                    Principals = 
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalArgs
                        {
                            Type = "AWS",
                            Identifiers = 
                            {
                                aws_cloudfront_origin_access_identity.Example.Iam_arn,
                            },
                        },
                    },
                },
            },
        }));
        var example = new Aws.S3.BucketPolicy("example", new Aws.S3.BucketPolicyArgs
        {
            Bucket = aws_s3_bucket.Example.Id,
            Policy = s3Policy.Apply(s3Policy => s3Policy.Json),
        });
    }

}

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var example = new Aws.CloudFront.OriginAccessIdentity("example", new Aws.CloudFront.OriginAccessIdentityArgs
        {
            Comment = "Some comment",
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudfront"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := cloudfront.NewOriginAccessIdentity(ctx, "example", &cloudfront.OriginAccessIdentityArgs{
			Comment: pulumi.String("Some comment"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

example = aws.cloudfront.OriginAccessIdentity("example", comment="Some comment")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.cloudfront.OriginAccessIdentity("example", {
    comment: "Some comment",
});

Create a OriginAccessIdentity Resource

new OriginAccessIdentity(name: string, args?: OriginAccessIdentityArgs, opts?: CustomResourceOptions);
@overload
def OriginAccessIdentity(resource_name: str,
                         opts: Optional[ResourceOptions] = None,
                         comment: Optional[str] = None)
@overload
def OriginAccessIdentity(resource_name: str,
                         args: Optional[OriginAccessIdentityArgs] = None,
                         opts: Optional[ResourceOptions] = None)
func NewOriginAccessIdentity(ctx *Context, name string, args *OriginAccessIdentityArgs, opts ...ResourceOption) (*OriginAccessIdentity, error)
public OriginAccessIdentity(string name, OriginAccessIdentityArgs? args = null, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args OriginAccessIdentityArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args OriginAccessIdentityArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args OriginAccessIdentityArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args OriginAccessIdentityArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

OriginAccessIdentity Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The OriginAccessIdentity resource accepts the following input properties:

Comment string
An optional comment for the origin access identity.
Comment string
An optional comment for the origin access identity.
comment string
An optional comment for the origin access identity.
comment str
An optional comment for the origin access identity.

Outputs

All input properties are implicitly available as output properties. Additionally, the OriginAccessIdentity resource produces the following output properties:

CallerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
CloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
Etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
IamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
Id string
The provider-assigned unique ID for this managed resource.
S3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
CallerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
CloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
Etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
IamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
Id string
The provider-assigned unique ID for this managed resource.
S3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
callerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
cloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
iamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
id string
The provider-assigned unique ID for this managed resource.
s3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
caller_reference str
Internal value used by CloudFront to allow future updates to the origin access identity.
cloudfront_access_identity_path str
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
etag str
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
iam_arn str
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
id str
The provider-assigned unique ID for this managed resource.
s3_canonical_user_id str
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.

Look up an Existing OriginAccessIdentity Resource

Get an existing OriginAccessIdentity resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: OriginAccessIdentityState, opts?: CustomResourceOptions): OriginAccessIdentity
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        caller_reference: Optional[str] = None,
        cloudfront_access_identity_path: Optional[str] = None,
        comment: Optional[str] = None,
        etag: Optional[str] = None,
        iam_arn: Optional[str] = None,
        s3_canonical_user_id: Optional[str] = None) -> OriginAccessIdentity
func GetOriginAccessIdentity(ctx *Context, name string, id IDInput, state *OriginAccessIdentityState, opts ...ResourceOption) (*OriginAccessIdentity, error)
public static OriginAccessIdentity Get(string name, Input<string> id, OriginAccessIdentityState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

CallerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
CloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
Comment string
An optional comment for the origin access identity.
Etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
IamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
S3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
CallerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
CloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
Comment string
An optional comment for the origin access identity.
Etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
IamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
S3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
callerReference string
Internal value used by CloudFront to allow future updates to the origin access identity.
cloudfrontAccessIdentityPath string
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
comment string
An optional comment for the origin access identity.
etag string
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
iamArn string
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
s3CanonicalUserId string
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.
caller_reference str
Internal value used by CloudFront to allow future updates to the origin access identity.
cloudfront_access_identity_path str
A shortcut to the full path for the origin access identity to use in CloudFront, see below.
comment str
An optional comment for the origin access identity.
etag str
The current version of the origin access identity’s information. For example: E2QWRUHAPOMQZL.
iam_arn str
A pre-generated ARN for use in S3 bucket policies (see below). Example: arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity E2QWRUHAPOMQZL.
s3_canonical_user_id str
The Amazon S3 canonical user ID for the origin access identity, which you use when giving the origin access identity read permission to an object in Amazon S3.

Import

Cloudfront Origin Access Identities can be imported using the id, e.g.,

 $ pulumi import aws:cloudfront/originAccessIdentity:OriginAccessIdentity origin_access E74FTE3AEXAMPLE

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.