CreateLocationS3
Creates a transfer location for an Amazon S3 bucket. AWS DataSync can use this location as a source or destination for transferring data.
Important
Before you begin, make sure that you read the following topics:
For more information, see Configuring transfers with Amazon S3.
Request Syntax
{
"AgentArns": [ "string
" ],
"S3BucketArn": "string
",
"S3Config": {
"BucketAccessRoleArn": "string
"
},
"S3StorageClass": "string
",
"Subdirectory": "string
",
"Tags": [
{
"Key": "string
",
"Value": "string
"
}
]
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- AgentArns
-
(Amazon S3 on Outposts only) Specifies the Amazon Resource Name (ARN) of the DataSync agent on your Outpost.
For more information, see Deploy your DataSync agent on AWS Outposts.
Type: Array of strings
Array Members: Minimum number of 1 item. Maximum number of 4 items.
Length Constraints: Maximum length of 128.
Pattern:
^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):datasync:[a-z\-0-9]+:[0-9]{12}:agent/agent-[0-9a-z]{17}$
Required: No
- S3BucketArn
-
Specifies the ARN of the S3 bucket that you want to use as a location. (When creating your DataSync task later, you specify whether this location is a transfer source or destination.)
If your S3 bucket is located on an AWS Outposts resource, you must specify an Amazon S3 access point. For more information, see Managing data access with Amazon S3 access points in the Amazon S3 User Guide.
Type: String
Length Constraints: Maximum length of 268.
Pattern:
^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):s3:[a-z\-0-9]*:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-.]{1,63}$|^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$|^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):s3:::[a-zA-Z0-9.\-_]{1,255}$
Required: Yes
- S3Config
-
Specifies the Amazon Resource Name (ARN) of the AWS Identity and Access Management (IAM) role that DataSync uses to access your S3 bucket.
For more information, see Providing DataSync access to S3 buckets.
Type: S3Config object
Required: Yes
- S3StorageClass
-
Specifies the storage class that you want your objects to use when Amazon S3 is a transfer destination.
For buckets in AWS Regions, the storage class defaults to
STANDARD
. For buckets on AWS Outposts, the storage class defaults toOUTPOSTS
.For more information, see Storage class considerations with Amazon S3 transfers.
Type: String
Valid Values:
STANDARD | STANDARD_IA | ONEZONE_IA | INTELLIGENT_TIERING | GLACIER | DEEP_ARCHIVE | OUTPOSTS | GLACIER_INSTANT_RETRIEVAL
Required: No
- Subdirectory
-
Specifies a prefix in the S3 bucket that DataSync reads from or writes to (depending on whether the bucket is a source or destination location).
Note
DataSync can't transfer objects with a prefix that begins with a slash (
/
) or includes//
,/./
, or/../
patterns. For example:-
/photos
-
photos//2006/January
-
photos/./2006/February
-
photos/../2006/March
Type: String
Length Constraints: Maximum length of 4096.
Pattern:
^[a-zA-Z0-9_\-\+\./\(\)\p{Zs}]*$
Required: No
-
- Tags
-
Specifies labels that help you categorize, filter, and search for your AWS resources. We recommend creating at least a name tag for your transfer location.
Type: Array of TagListEntry objects
Array Members: Minimum number of 0 items. Maximum number of 50 items.
Required: No
Response Syntax
{
"LocationArn": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- LocationArn
-
The ARN of the S3 location that you created.
Type: String
Length Constraints: Maximum length of 128.
Pattern:
^arn:(aws|aws-cn|aws-us-gov|aws-iso|aws-iso-b):datasync:[a-z\-0-9]+:[0-9]{12}:location/loc-[0-9a-z]{17}$
Errors
For information about the errors that are common to all actions, see Common Errors.
- InternalException
-
This exception is thrown when an error occurs in the AWS DataSync service.
HTTP Status Code: 500
- InvalidRequestException
-
This exception is thrown when the client submits a malformed request.
HTTP Status Code: 400
Examples
Step 1. Allow to assume the IAM role required to write to the bucket
The following example shows the simplest policy that grants the required permissions
for AWS DataSync to access a destination Amazon S3 bucket, followed by an IAM
role to which the create-location-s3-iam-role
policy has been
attached.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "datasync.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
"Role": { "Path": "/", "RoleName": "amzn-s3-demo-bucket-access-role", "RoleId": "role-id", "Arn": "arn:aws:iam::account-id:role/amzn-s3-demo-bucket-access-role", "CreateDate": "2018-07-27T02:49:23.117Z", "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "datasync.amazonaws.com" }, "Action": "sts:AssumeRole" } ] } } }
Step 2. Allow the created IAM role to write to the bucket
Attach a policy that has sufficient permissions to access the bucket to the role. An
example of such policy is the AWSDataSyncFullAccess
managed policy.
For more information, see AWSDataSyncFullAccess
You don't need to create this policy. It's managed by AWS, so
all that you need to do is specify its ARN in the attach-role-policy
command.
IAM_POLICY_ARN='arn:aws:iam::aws:policy/AWSDataSyncFullAccess'
Step 3. Create an endpoint for an Amazon S3 bucket
The following example creates an endpoint for an Amazon S3 bucket.
When the S3 endpoint is created, a response similar to the second example following returns the Amazon Resource Name (ARN) for the new Amazon S3 location.
Sample Request
{
"S3BucketArn": "arn:aws:s3:::amzn-s3-demo-bucket",
"S3Config": {
"BucketAccessRoleArn": "arn:aws:iam::111222333444:role/amzn-s3-demo-bucket-access-role",
},
"S3StorageClass": "STANDARD",
"Subdirectory": "/MyFolder",
"Tags": [
{
"Key": "Name",
"Value": "s3Bucket-1"
}
]
}
Sample Response
{
"LocationArn": "arn:aws:datasync:us-east-2:111222333444:location/loc-07db7abfc326c50s3"
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: