Movatterモバイル変換


[0]ホーム

URL:


AWS CLI Command Reference

Navigation

Amazon Web Services logo

Table of Contents

Quick search

Feedback

Did you find this page useful? Do you have a suggestion to improve the documentation?Give us feedback.
If you would like to suggest an improvement or fix for the AWS CLI, check out ourcontributing guide on GitHub.

User Guide

First time using the AWS CLI? See theUser Guide for help getting started.

[aws .s3api ]

put-bucket-cors

Description

Note

This operation is not supported for directory buckets.

Sets thecors configuration for your bucket. If the configuration exists, Amazon S3 replaces it.

To use this operation, you must be allowed to perform thes3:PutBucketCORS action. By default, the bucket owner has this permission and can grant it to others.

You set this configuration on a bucket so that the bucket can service cross-origin requests. For example, you might want to enable a request whose origin ishttp://www.example.com to access your Amazon S3 bucket atmy.example.bucket.com by using the browser’sXMLHttpRequest capability.

To enable cross-origin resource sharing (CORS) on a bucket, you add thecors subresource to the bucket. Thecors subresource is an XML document in which you configure rules that identify origins and the HTTP methods that can be executed on your bucket. The document is limited to 64 KB in size.

When Amazon S3 receives a cross-origin request (or a pre-flight OPTIONS request) against a bucket, it evaluates thecors configuration on the bucket and uses the firstCORSRule rule that matches the incoming browser request to enable a cross-origin request. For a rule to match, the following conditions must be met:

  • The request’sOrigin header must matchAllowedOrigin elements.
  • The request method (for example, GET, PUT, HEAD, and so on) or theAccess-Control-Request-Method header in case of a pre-flightOPTIONS request must be one of theAllowedMethod elements.
  • Every header specified in theAccess-Control-Request-Headers request header of a pre-flight request must match anAllowedHeader element.

For more information about CORS, go toEnabling Cross-Origin Resource Sharing in theAmazon S3 User Guide .

The following operations are related toPutBucketCors :

Warning

You must URL encode any signed header values that contain spaces. For example, if your header value ismyfile.txt , containing two spaces aftermy , you must URL encode this value tomy%20%20file.txt .

See also:AWS API Documentation

Synopsis

put-bucket-cors--bucket<value>--cors-configuration<value>[--content-md5<value>][--checksum-algorithm<value>][--expected-bucket-owner<value>][--cli-input-json|--cli-input-yaml][--generate-cli-skeleton<value>][--debug][--endpoint-url<value>][--no-verify-ssl][--no-paginate][--output<value>][--query<value>][--profile<value>][--region<value>][--version<value>][--color<value>][--no-sign-request][--ca-bundle<value>][--cli-read-timeout<value>][--cli-connect-timeout<value>][--cli-binary-format<value>][--no-cli-pager][--cli-auto-prompt][--no-cli-auto-prompt]

Options

--bucket (string) [required]

Specifies the bucket impacted by thecors configuration.

--cors-configuration (structure) [required]

Describes the cross-origin access configuration for objects in an Amazon S3 bucket. For more information, seeEnabling Cross-Origin Resource Sharing in theAmazon S3 User Guide .

CORSRules -> (list) [required]

A set of origins and methods (cross-origin access that you want to allow). You can add up to 100 rules to the configuration.

(structure)

Specifies a cross-origin access rule for an Amazon S3 bucket.

ID -> (string)

Unique identifier for the rule. The value cannot be longer than 255 characters.

AllowedHeaders -> (list)

Headers that are specified in theAccess-Control-Request-Headers header. These headers are allowed in a preflight OPTIONS request. In response to any preflight OPTIONS request, Amazon S3 returns any requested headers that are allowed.

(string)

AllowedMethods -> (list) [required]

An HTTP method that you allow the origin to execute. Valid values areGET ,PUT ,HEAD ,POST , andDELETE .

(string)

AllowedOrigins -> (list) [required]

One or more origins you want customers to be able to access the bucket from.

(string)

ExposeHeaders -> (list)

One or more headers in the response that you want customers to be able to access from their applications (for example, from a JavaScriptXMLHttpRequest object).

(string)

MaxAgeSeconds -> (integer)

The time in seconds that your browser is to cache the preflight response for the specified resource.

JSON Syntax:

{"CORSRules":[{"ID":"string","AllowedHeaders":["string",...],"AllowedMethods":["string",...],"AllowedOrigins":["string",...],"ExposeHeaders":["string",...],"MaxAgeSeconds":integer}...]}

--content-md5 (string)

The Base64 encoded 128-bitMD5 digest of the data. This header must be used as a message integrity check to verify that the request body was not corrupted in transit. For more information, go toRFC 1864.

For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.

--checksum-algorithm (string)

Indicates the algorithm used to create the checksum for the request when you use the SDK. This header will not provide any additional functionality if you don’t use the SDK. When you send this header, there must be a correspondingx-amz-checksum orx-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the HTTP status code400BadRequest . For more information, seeChecking object integrity in theAmazon S3 User Guide .

If you provide an individual checksum, Amazon S3 ignores any providedChecksumAlgorithm parameter.

Possible values:

  • CRC32
  • CRC32C
  • SHA1
  • SHA256
  • CRC64NVME

--expected-bucket-owner (string)

The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code403Forbidden (access denied).

--cli-input-json |--cli-input-yaml (string)Reads arguments from the JSON string provided. The JSON string follows the format provided by--generate-cli-skeleton. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with--cli-input-yaml.

--generate-cli-skeleton (string)Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the valueinput, prints a sample input JSON that can be used as an argument for--cli-input-json. Similarly, if providedyaml-input it will print a sample input YAML that can be used with--cli-input-yaml. If provided with the valueoutput, it validates the command inputs and returns a sample output JSON for that command. The generated JSON skeleton is not stable between versions of the AWS CLI and there are no backwards compatibility guarantees in the JSON skeleton generated.

Global Options

--debug (boolean)

Turn on debug logging.

--endpoint-url (string)

Override command’s default URL with the given URL.

--no-verify-ssl (boolean)

By default, the AWS CLI uses SSL when communicating with AWS services. For each SSL connection, the AWS CLI will verify SSL certificates. This option overrides the default behavior of verifying SSL certificates.

--no-paginate (boolean)

Disable automatic pagination. If automatic pagination is disabled, the AWS CLI will only make one call, for the first page of results.

--output (string)

The formatting style for command output.

  • json
  • text
  • table
  • yaml
  • yaml-stream

--query (string)

A JMESPath query to use in filtering the response data.

--profile (string)

Use a specific profile from your credential file.

--region (string)

The region to use. Overrides config/env settings.

--version (string)

Display the version of this tool.

--color (string)

Turn on/off color output.

  • on
  • off
  • auto

--no-sign-request (boolean)

Do not sign requests. Credentials will not be loaded if this argument is provided.

--ca-bundle (string)

The CA certificate bundle to use when verifying SSL certificates. Overrides config/env settings.

--cli-read-timeout (int)

The maximum socket read time in seconds. If the value is set to 0, the socket read will be blocking and not timeout. The default value is 60 seconds.

--cli-connect-timeout (int)

The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.

--cli-binary-format (string)

The formatting style to be used for binary blobs. The default format is base64. The base64 format expects binary blobs to be provided as a base64 encoded string. The raw-in-base64-out format preserves compatibility with AWS CLI V1 behavior and binary values must be passed literally. When providing contents from a file that map to a binary blobfileb:// will always be treated as binary and use the file contents directly regardless of thecli-binary-format setting. When usingfile:// the file contents will need to properly formatted for the configuredcli-binary-format.

  • base64
  • raw-in-base64-out

--no-cli-pager (boolean)

Disable cli pager for output.

--cli-auto-prompt (boolean)

Automatically prompt for CLI input parameters.

--no-cli-auto-prompt (boolean)

Disable automatically prompt for CLI input parameters.

Examples

Note

To use the following examples, you must have the AWS CLI installed and configured. See theGetting started guide in theAWS CLI User Guide for more information.

Unless otherwise stated, all examples have unix-like quotation rules. These examples will need to be adapted to your terminal’s quoting rules. SeeUsing quotation marks with strings in theAWS CLI User Guide .

The following example enablesPUT,POST, andDELETE requests fromwww.example.com, and enablesGETrequests from any domain:

awss3apiput-bucket-cors--bucketamzn-s3-demo-bucket--cors-configurationfile://cors.jsoncors.json:{"CORSRules":[{"AllowedOrigins":["http://www.example.com"],"AllowedHeaders":["*"],"AllowedMethods":["PUT","POST","DELETE"],"MaxAgeSeconds":3000,"ExposeHeaders":["x-amz-server-side-encryption"]},{"AllowedOrigins":["*"],"AllowedHeaders":["Authorization"],"AllowedMethods":["GET"],"MaxAgeSeconds":3000}]}

Output

None

Navigation

© Copyright 2025, Amazon Web Services. Created usingSphinx.

[8]ページ先頭

©2009-2025 Movatter.jp