|
| 1 | +package cp |
| 2 | + |
| 3 | +const cp_examples = `Example 1: Copying a local file to S3 |
| 4 | +
|
| 5 | + The following cp command copies a single file to a specified bucket and |
| 6 | + key: |
| 7 | +
|
| 8 | + aws s3 cp test.txt s3://amzn-s3-demo-bucket/test2.txt |
| 9 | +
|
| 10 | + Output: |
| 11 | +
|
| 12 | + upload: test.txt to s3://amzn-s3-demo-bucket/test2.txt |
| 13 | +
|
| 14 | + Example 2: Copying a local file to S3 with an expiration date |
| 15 | +
|
| 16 | + The following cp command copies a single file to a specified bucket and |
| 17 | + key that expires at the specified ISO 8601 timestamp: |
| 18 | +
|
| 19 | + aws s3 cp test.txt s3://amzn-s3-demo-bucket/test2.txt \ |
| 20 | + --expires 2014-10-01T20:30:00Z |
| 21 | +
|
| 22 | + Output: |
| 23 | +
|
| 24 | + upload: test.txt to s3://amzn-s3-demo-bucket/test2.txt |
| 25 | +
|
| 26 | + Example 3: Copying a file from S3 to S3 |
| 27 | +
|
| 28 | + The following cp command copies a single s3 object to a specified |
| 29 | + bucket and key: |
| 30 | +
|
| 31 | + aws s3 cp s3://amzn-s3-demo-bucket/test.txt s3://amzn-s3-demo-bucket/test2.txt |
| 32 | +
|
| 33 | + Output: |
| 34 | +
|
| 35 | + copy: s3://amzn-s3-demo-bucket/test.txt to s3://amzn-s3-demo-bucket/test2.txt |
| 36 | +
|
| 37 | + Example 4: Copying an S3 object to a local file |
| 38 | +
|
| 39 | + The following cp command copies a single object to a specified file lo- |
| 40 | + cally: |
| 41 | +
|
| 42 | + aws s3 cp s3://amzn-s3-demo-bucket/test.txt test2.txt |
| 43 | +
|
| 44 | + Output: |
| 45 | +
|
| 46 | + download: s3://amzn-s3-demo-bucket/test.txt to test2.txt |
| 47 | +
|
| 48 | + Example 5: Copying an S3 object from one bucket to another |
| 49 | +
|
| 50 | + The following cp command copies a single object to a specified bucket |
| 51 | + while retaining its original name: |
| 52 | +
|
| 53 | + aws s3 cp s3://amzn-s3-demo-bucket/test.txt s3://amzn-s3-demo-bucket2/ |
| 54 | +
|
| 55 | + Output: |
| 56 | +
|
| 57 | + copy: s3://amzn-s3-demo-bucket/test.txt to s3://amzn-s3-demo-bucket2/test.txt |
| 58 | +
|
| 59 | + Example 6: Recursively copying S3 objects to a local directory |
| 60 | +
|
| 61 | + When passed with the parameter --recursive, the following cp command |
| 62 | + recursively copies all objects under a specified prefix and bucket to a |
| 63 | + specified directory. In this example, the bucket amzn-s3-demo-bucket |
| 64 | + has the objects test1.txt and test2.txt: |
| 65 | +
|
| 66 | + aws s3 cp s3://amzn-s3-demo-bucket . \ |
| 67 | + --recursive |
| 68 | +
|
| 69 | + Output: |
| 70 | +
|
| 71 | + download: s3://amzn-s3-demo-bucket/test1.txt to test1.txt |
| 72 | + download: s3://amzn-s3-demo-bucket/test2.txt to test2.txt |
| 73 | +
|
| 74 | + Example 7: Recursively copying local files to S3 |
| 75 | +
|
| 76 | + When passed with the parameter --recursive, the following cp command |
| 77 | + recursively copies all files under a specified directory to a specified |
| 78 | + bucket and prefix while excluding some files by using an --exclude pa- |
| 79 | + rameter. In this example, the directory myDir has the files test1.txt |
| 80 | + and test2.jpg: |
| 81 | +
|
| 82 | + aws s3 cp myDir s3://amzn-s3-demo-bucket/ \ |
| 83 | + --recursive \ |
| 84 | + --exclude "*.jpg" |
| 85 | +
|
| 86 | + Output: |
| 87 | +
|
| 88 | + upload: myDir/test1.txt to s3://amzn-s3-demo-bucket/test1.txt |
| 89 | +
|
| 90 | + Example 8: Recursively copying S3 objects to another bucket |
| 91 | +
|
| 92 | + When passed with the parameter --recursive, the following cp command |
| 93 | + recursively copies all objects under a specified bucket to another |
| 94 | + bucket while excluding some objects by using an --exclude parameter. |
| 95 | + In this example, the bucket amzn-s3-demo-bucket has the objects |
| 96 | + test1.txt and another/test1.txt: |
| 97 | +
|
| 98 | + aws s3 cp s3://amzn-s3-demo-bucket/ s3://amzn-s3-demo-bucket2/ \ |
| 99 | + --recursive \ |
| 100 | + --exclude "another/*" |
| 101 | +
|
| 102 | + Output: |
| 103 | +
|
| 104 | + copy: s3://amzn-s3-demo-bucket/test1.txt to s3://amzn-s3-demo-bucket2/test1.txt |
| 105 | +
|
| 106 | + You can combine --exclude and --include options to copy only objects |
| 107 | + that match a pattern, excluding all others: |
| 108 | +
|
| 109 | + aws s3 cp s3://amzn-s3-demo-bucket/logs/ s3://amzn-s3-demo-bucket2/logs/ \ |
| 110 | + --recursive \ |
| 111 | + --exclude "*" \ |
| 112 | + --include "*.log" |
| 113 | +
|
| 114 | + Output: |
| 115 | +
|
| 116 | + copy: s3://amzn-s3-demo-bucket/logs/test/test.log to s3://amzn-s3-demo-bucket2/logs/test/test.log |
| 117 | + copy: s3://amzn-s3-demo-bucket/logs/test3.log to s3://amzn-s3-demo-bucket2/logs/test3.log |
| 118 | +
|
| 119 | + Example 9: Setting the Access Control List (ACL) while copying an S3 |
| 120 | + object |
| 121 | +
|
| 122 | + The following cp command copies a single object to a specified bucket |
| 123 | + and key while setting the ACL to public-read-write: |
| 124 | +
|
| 125 | + aws s3 cp s3://amzn-s3-demo-bucket/test.txt s3://amzn-s3-demo-bucket/test2.txt \ |
| 126 | + --acl public-read-write |
| 127 | +
|
| 128 | + Output: |
| 129 | +
|
| 130 | + copy: s3://amzn-s3-demo-bucket/test.txt to s3://amzn-s3-demo-bucket/test2.txt |
| 131 | +
|
| 132 | + Note that if you're using the --acl option, ensure that any associated |
| 133 | + IAM policies include the "s3:PutObjectAcl" action: |
| 134 | +
|
| 135 | + aws iam get-user-policy \ |
| 136 | + --user-name myuser \ |
| 137 | + --policy-name mypolicy |
| 138 | +
|
| 139 | + Output: |
| 140 | +
|
| 141 | + { |
| 142 | + "UserName": "myuser", |
| 143 | + "PolicyName": "mypolicy", |
| 144 | + "PolicyDocument": { |
| 145 | + "Version": "2012-10-17", |
| 146 | + "Statement": [ |
| 147 | + { |
| 148 | + "Action": [ |
| 149 | + "s3:PutObject", |
| 150 | + "s3:PutObjectAcl" |
| 151 | + ], |
| 152 | + "Resource": [ |
| 153 | + "arn:aws:s3:::amzn-s3-demo-bucket/*" |
| 154 | + ], |
| 155 | + "Effect": "Allow", |
| 156 | + "Sid": "Stmt1234567891234" |
| 157 | + } |
| 158 | + ] |
| 159 | + } |
| 160 | + } |
| 161 | +
|
| 162 | + Example 10: Granting permissions for an S3 object |
| 163 | +
|
| 164 | + The following cp command illustrates the use of the --grants option to |
| 165 | + grant read access to all users identified by URI and full control to a |
| 166 | + specific user identified by their Canonical ID: |
| 167 | +
|
| 168 | + aws s3 cp file.txt s3://amzn-s3-demo-bucket/ --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers full=id=79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be |
| 169 | +
|
| 170 | + Output: |
| 171 | +
|
| 172 | + upload: file.txt to s3://amzn-s3-demo-bucket/file.txt |
| 173 | +
|
| 174 | + Example 11: Uploading a local file stream to S3 |
| 175 | +
|
| 176 | + WARNING: |
| 177 | + PowerShell may alter the encoding of or add a CRLF to piped input. |
| 178 | +
|
| 179 | + The following cp command uploads a local file stream from standard in- |
| 180 | + put to a specified bucket and key: |
| 181 | +
|
| 182 | + aws s3 cp - s3://amzn-s3-demo-bucket/stream.txt |
| 183 | +
|
| 184 | + Example 12: Uploading a local file stream that is larger than 50GB to |
| 185 | + S3 |
| 186 | +
|
| 187 | + The following cp command uploads a 51GB local file stream from standard |
| 188 | + input to a specified bucket and key. The --expected-size option must |
| 189 | + be provided, or the upload may fail when it reaches the default part |
| 190 | + limit of 10,000: |
| 191 | +
|
| 192 | + aws s3 cp - s3://amzn-s3-demo-bucket/stream.txt --expected-size 54760833024 |
| 193 | +
|
| 194 | + Example 13: Downloading an S3 object as a local file stream |
| 195 | +
|
| 196 | + WARNING: |
| 197 | + PowerShell may alter the encoding of or add a CRLF to piped or redi- |
| 198 | + rected output. |
| 199 | +
|
| 200 | + The following cp command downloads an S3 object locally as a stream to |
| 201 | + standard output. Downloading as a stream is not currently compatible |
| 202 | + with the --recursive parameter: |
| 203 | +
|
| 204 | + aws s3 cp s3://amzn-s3-demo-bucket/stream.txt - |
| 205 | +
|
| 206 | + Example 14: Uploading to an S3 access point |
| 207 | +
|
| 208 | + The following cp command uploads a single file (mydoc.txt) to the ac- |
| 209 | + cess point (myaccesspoint) at the key (mykey): |
| 210 | +
|
| 211 | + aws s3 cp mydoc.txt s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/mykey |
| 212 | +
|
| 213 | + Output: |
| 214 | +
|
| 215 | + upload: mydoc.txt to s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/mykey |
| 216 | +
|
| 217 | + Example 15: Downloading from an S3 access point |
| 218 | +
|
| 219 | + The following cp command downloads a single object (mykey) from the ac- |
| 220 | + cess point (myaccesspoint) to the local file (mydoc.txt): |
| 221 | +
|
| 222 | + aws s3 cp s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/mykey mydoc.txt |
| 223 | +
|
| 224 | + Output: |
| 225 | +
|
| 226 | + download: s3://arn:aws:s3:us-west-2:123456789012:accesspoint/myaccesspoint/mykey to mydoc.txt |
| 227 | +` |
0 commit comments