ECS: S3 AWS CLI configureren en gebruiken
Summary: Wanneer u AWS CLI gebruikt om klantscenario's te testen waarin ze AWS CLI gebruiken met ECS om functionaliteit en compatibiliteit te bevestigen, raadpleeg dan altijd de ECS Data Access Guide voor ECS AWS S3 ondersteunde API-aanroepen. ...
Instructions
AWS Command-Line Interface (AWS CLI) is een tool van AWS die kan worden gebruikt om S3-opdrachten op hoog niveau te testen en s3 API-niveau (s3api)
Opdrachten op hoog niveau aws s3 (externe koppeling) ondersteunen veelvoorkomende bucket-bewerkingen, zoals het maken, weergeven en verwijderen van buckets. Hoe de tool te downloaden en te installeren, alle ondersteunde opdrachten op hoog niveau kunnen worden verkregen in de opdrachtset met behulp van de opdracht aws s3api help.
S3Uri: Vertegenwoordigt de locatie van een S3-object, voorvoegsel of bucket - Dit moet in het formulier worden geschreven s3://mybucket/mykey waar -. mybucket t gespecificeerde S3-emmer is, mykey is de opgegeven S3-toets. Het pad-argument moet beginnen met s3://
AWS s3api-opdrachten (externe koppeling) op API-niveau zijn opgenomen in de s3api commend-set. Deze S3 API-opdrachten bieden toegang tot bucket-metadata, zoals bucket ACL, bucketbeleid, levenscyclusbeleid om er maar een paar te noemen, alle ondersteunde API-aanroepen kunnen worden verkregen in de opdrachtset met behulp van de opdracht aws s3api help.
- AWS CLI gebruikt standaard automatisch maximaal 10 threads om bestanden of onderdelen te uploaden tijdens uploads
- De AWS CLI gebruikt automatisch multipart_threshold uploads voor bestanden >= 8 MB bestandsgrootte, multipart_chunksize
Download- en installatie-instructies.
- Versie releases https://github.com/aws/aws-cli/releases (External Link)
- Download en installeer de AWS CLI bundel
# curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
- Bundel uitpakken
# unzip awscli-bundle.zip
- Voer de installatieopdracht uit
# sudo /awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
- Versie bevestigen
# aws version
Output: aws-cli/2.0.33 Python/3.7.3 Linux/4.15.0-109-generic botocore/2.0.0dev37
De AWS CLI configureren
In dit gedeelte worden de basisstappen uitgelegd voor het configureren van AWS CLI voor gebruik met ECS S3, met behulp van de ECS-objectgebruiker. In dit gedeelte wordt ervan uitgegaan dat bucket en objectgebruiker al zijn gemaakt op ECS. De referenties en het configuratiebestand worden bijgewerkt wanneer u de opdracht uitvoertaws configure.
Het referentiesbestand vindt u hier
~/.aws/credentials. In het referentiebestand worden gebruikersprofielgegevens opgeslagen (toegangssleutel-ID en geheime toegangssleutels), in het configuratiebestand worden regio- en uitvoerformaatgegevens opgeslagen.
Vereist:
- Toegangssleutel-ID: ECS object gebruiker
- Geheime toegangssleutel: Geheime sleutel
- In dit voorbeeld wordt een profielnaam gemaakt mc_s3
# aws configure --profile mc_s3
Prompt:
AWS Access Key ID [None]: mc_s3
AWS Secret Access Key [None]: 1guFemRLSgqFau6uKzIVAZJu5+PS+S8qO7rvEsi7
Default region name [None]:
Default output format [None]: json
- Lijstprofielen: alle profielen (lijst-eigenschappen beschikbaar in AWS CLI v2
# aws configure list-properties
Output:
mc_s3
ad_uid1
# aws configure list
Output: Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************c_s3 shared-credentials-file secret_key ****************Esi7 shared-credentials-file region config-file ~/.aws/config
- Lijstspecifiek profiel
# aws configure get aws_access_key_id --profile mc_s3
Output:
mc_s3
Dealing with SSL connections and error on self signed certificate. ( [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056))
- Als u opdrachten gebruikt op 9021, is de AWS CLI-optie
--no-verify-sslis vereist om de fout met het zelfondertekende certificaat te omzeilen.
# aws --profile mc_s3 --endpoint=https://ecshop:9021 s3api list-buckets
Output:
SSL validation failed for https://ecshop:9021/mc_s3_bkt?acl [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056)
- Opdracht uitvoeren met
--no-verifyOptie om deze fout te omzeilen
# aws --profile mc_s3 --endpoint=https://ecshop:9021 s3api list-buckets --no-verify-ssl --output text
Output: /usr/local/aws-cli/v2/2.0.33/dist/urllib3/connectionpool.py:986: InsecureRequestWarning: Unverified HTTPS request is being made to host 'ecshop'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings BUCKETS 2020-02-24T21:24:29.440000+00:00 mc_s3_bkt BUCKETS 2020-05-06T17:23:48.870000+00:00 mc_s3_bkt2_backup BUCKETS 2020-05-06T21:16:13.344000+00:00 mc_s3_bkt_nfs OWNER mc_s3 mc_s3
- De tweede optie is om het zelfondertekende ECS-certificaat te downloaden dat is opgeslagen in PEM-indeling en met behulp van de
--ca-bundleoptie - Gebruik OpenSSL om een ECS-certificaat te verkrijgen voor toegang tot objectdata op poort 9021 en kopieer de inhoud van het certificaat met behulp van uw favoriete editor en sla op, inclusief certificaatkopteksten per voorbeeld hieronder.
# openssl s_client -connect ecshop:9021
ecshop is het IP-adres of de hostnaam van de ECS-knooppunten, en xxxxxx moet het volledige certificaat in uw omgeving zijn.
Output: -----BEGIN CERTIFICATE----- Xxxxxxxxx xxxxxxxxx ... ... -----END CERTIFICATE-----
- Maak een lijst van buckets in de tabel Mensvriendelijk met ca-bundeloptie waarbij het certificaat wordt opgeslagen in PEM-bestandsnaam ecshop_cert_pem
# aws --profile mc_s3 --endpoint=https://ecshop:9021 s3api list-buckets --ca-bundle ecshop_cert.pem --output table
Output: ------------------------------------------------------------- | ListBuckets | +-----------------------------------------------------------+ || Buckets || |+-----------------------------------+---------------------+| || CreationDate | Name || |+-----------------------------------+---------------------+| || 2020-02-24T21:24:29.440000+00:00 | mc_s3_bkt || || 2020-05-06T17:23:48.870000+00:00 | mc_s3_bkt2_backup || || 2020-05-06T21:16:13.344000+00:00 | mc_s3_bkt_nfs || |+-----------------------------------+---------------------+| || Owner || |+-----------------------------------+---------------------+| || DisplayName | ID || |+-----------------------------------+---------------------+| || mc_s3 | mc_s3 || |+-----------------------------------+---------------------+|
Basis S3-bewerkingen
https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html (Externe link)Prestaties afstemmen
- max_concurrent_requests - Het maximum aantal gelijktijdige aanvragen
- max_queue_size - Het maximale aantal taken in de takenwachtrij
- multipart_threshold - De drempelwaarde voor grootte die de CLI gebruikt voor meervoudige overdrachten van afzonderlijke bestanden.
- multipart_chunksize - Bij meervoudige overdrachten is dit de segmentgrootte die de CLI gebruikt voor meerdelige overdrachten van afzonderlijke bestanden.
- max_bandwidth - De maximale bandbreedte die wordt verbruikt voor het uploaden en downloaden van data van en naar Amazon S3.
# cat .aws/config
Output: [profile mc_s3] output = json s3 = endpoint_url = http://ecshop:9020 max_concurrent_requests = 20 max_queue_size = 1000 multipart_threshold = 64MB multipart_chunksize = 16MB max_bandwidth = 50MB/s addressing_style = autoGebruik
aws configure set Opdracht om parameters in te stellen voor het afstemmen van uploadsnelheden
$ aws configure set default.s3.max_concurrent_requests 20 $ aws configure set default.s3.max_queue_size 10000 $ aws configure set default.s3.multipart_threshold 64MB $ aws configure set default.s3.multipart_chunksize 16MB $ aws configure set default.s3.max_bandwidth 50MB/s $ aws configure set default.s3.addressing_style autoStappen:
- Bucket maken met
s3 mbbevelen
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 mb s3://s3_bkt
Output:
make_bucket: s3_bkt
- Lijstbuckets met
s3 lsalss3api list-bucketscommand sets lijsten buckets, voor alle andere bewerkingen (in S3 aangeduid als 'prefixes') (External Link) in een bucket
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 ls
Output:
2020-07-29 20:34:24 s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-buckets
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-buckets
Output:
aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-buckets
{
"Buckets": [
{
"Name": "mc_s3_bkt",
"CreationDate": "2020-02-24T21:24:29.440000+00:00"
},
{
"Name": "mc_s3_bkt2_backup",
"CreationDate": "2020-05-06T17:23:48.870000+00:00"
},
{
"Name": "mc_s3_bkt_nfs",
"CreationDate": "2020-05-06T21:16:13.344000+00:00"
},
{
"Name": "s3_bkt",
"CreationDate": "2020-07-30T00:34:24.147000+00:00"
},
- Bestanden maken en uploaden om te testen
- Voorbeeld van het maken van bestanden van 1 MB en 4 MB
# dd if=/dev/zero of=1MB_output.file bs=1024 count=1024 # dd if=/dev/zero of=4MB_output.file bs=1024 count=4096
- Voorbeeld van het maken van een groot bestand 2 GB
# dd if=/dev/urandom of=bigfile_2GB bs=1024k count=2048
- Bestand van 1 MB uploaden naar bucket
s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 cp 1MB_output.file s3://s3_bkt
Output:
upload: ./1MB_output.file to s3://s3_bkt/1MB_output.file
- Maak een lijst van bestanden in bucket,
s3_bktProfielnaam gebruiken mc_s3 gebruikens3 lsofs3api list-objectsOpdrachtensets
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 ls s3://s3_bkt
Output: 2020-07-29 20:39:43 16.0 MiB 16MB_output.file 2020-07-29 20:37:25 1.0 MiB 1MB_output.file 2020-07-29 20:39:23 4.0 MiB 4MB_output.file
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-objects --bucket s3_bkt Output: { "Contents": [ { "Key": "16MB_output.file", "LastModified": "2020-07-30T00:39:43.125000+00:00", "ETag": "\"3a2d20e2e504fe056bbaae5b4c2351fd-2\"", "Size": 16777216, "StorageClass": "STANDARD", "Owner": { "DisplayName": "mc_s3", "ID": "mc_s3" } }, { "Key": "1MB_output.file", "LastModified": "2020-07-30T00:37:25.033000+00:00", "ETag": "\"b6d81b360a5672d80c27430f39153e2c\"", "Size": 1048576, "StorageClass": "STANDARD", "Owner": { "DisplayName": "mc_s3", "ID": "mc_s3" } },
- Objectversies weergeven
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-object-versions --bucket s3_bkt --output text
- Download bestand, 1MB_output.file van
s3_bktnaar /tmp directory op de lokale computer.
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 cp s3://s3_bkt/1MB_output.file /tmp/
Output:
download: s3://s3_bkt/1MB_output.file to ../../tmp/1MB_output.file
- Controleer de ACL van een bestand 1MB_output.-bestand in YAML-indeling voor uitvoer op leesbaarheid
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-object-acl --bucket s3_bkt --key 1MB_output.file --output yaml
Output: Grants: - Grantee: DisplayName: mc_s3 ID: mc_s3 Type: CanonicalUser Permission: FULL_CONTROL Owner: DisplayName: mc_s3 ID: mc_s3
- Controleer bucket ACL op bucket
s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-acl --bucket s3_bkt --output yaml
Output: Grants: - Grantee: DisplayName: mc_s3 ID: mc_s3 Type: CanonicalUser Permission: FULL_CONTROL Owner: DisplayName: mc_s3 ID: mc_s3
- Controleer de bucketversie of schakel versiebeheer op de bucket in
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output:
{
"Status": "Enabled"
}
- Uploaden van meerdere onderdelen starten met behulp van s3api API-niveau met een groot bestand
- Maak een bestand van 5 GB:
# time dd if=/dev/urandom of=bigfile_5GB bs=1024k count=5096
- Upload starten
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api create-multipart-upload --bucket s3_bkt --key bigfile_5GB
Output:
{
"Bucket": "s3_bkt",
"Key": "bigfile_5GB",
"UploadId": "27cb6c45ab5c4c838fb5893263d871d3"
}
- Lijst van onvolledige meerdelige bestandsuploads https://aws.amazon.com/premiumsupport/knowledge-center/s3-multipart-upload-cli/ (Externe link)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-multipart-uploads --bucket s3_bkt
Output:
{
"Uploads": [
{
"UploadId": "27cb6c45ab5c4c838fb5893263d871d3",
"Key": "bigfile_5GB",
"Initiated": "2020-07-31T01:10:56.323000+00:00",
"StorageClass": "STANDARD",
"Owner": {
"DisplayName": "mc_s3",
"ID": "mc_s3"
}
}
]
}
- Verbeteren
s3 cpCommand of bucket-to-bucket prestatie-aanbevelingen voor grote bestanden om uploads van meerdere delen en het wijzigen van gelijktijdige threads te initiëren, zie hierboven onder prestatieafstemming.
- Voer bucket-naar-bucket-kopie uit om file.txt in te kopiëren
mc_s3_bktAans3_bktmet behulp van S3api
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api copy-object --copy-source mc_s3_bkt/file.txt --key file.txt --bucket s3_bkt
Output:
{
"VersionId": "1596159769267",
"CopyObjectResult": {
"ETag": "\"c789e490a90359de2bd3b09d7e957cfd-128\"",
"LastModified": "2020-07-31T01:42:49.267000+00:00"
}
}
- Bestanden (objecten of sleutels) in een bucket vermelden
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 ls s3://s3_bkt/file.txt --human-readable summarize
Output:
2020-07-30 21:42:49 1.0 GiB file.txt
- Een bestand kopiëren uit
S3_bktAanmc_s3_bktDe S3 CP-opdrachtenset op hoog niveau gebruiken
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 cp s3://s3_bkt/file.txt s3://mc_s3_bkt/file2.txt
Output: copy: s3://s3_bkt/file.txt to s3://mc_s3_bkt/file2.txt
- Controleren of versiebeheer is ingeschakeld op bucket
s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output:
{
"Status": "Enabled"
}
- Bucket verwijderen met
s3 rbCommand (command has no output)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 rm s3://s3_bkt2
- In het volgende voorbeeld worden alle objecten en submappen in de bucket verwijderd en vervolgens de bucket verwijderd. (als versiebeheer is ingeschakeld, worden met deze opdracht geen versieobjecten verwijderd (bekijk LDS, Levenscyclusbeleid)
# aws s3 rb s3://bucket-name --force
- Versiebeheer op bucket inschakelen
s3_bktmet behulp van opdracht op s3api API-niveau (opdracht heeft geen uitvoer)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-versioning --bucket s3_bkt --versioning-configuration Status=Enabled
- Levenscyclusbeleid toepassen Sjabloon genereren (referentie ECS Data Access Guide) AWS CLI vereist json-indeling voor levenscyclusbeleid
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-lifecycle-configuration --generate-cli-skeleton input --bucket s3_bkt
- Pas het beleid voor de levensduur van de bucket toe op de bucket. Raadpleeg voor meer informatie de ECS Data Access Guide
AbortIncompleteMultipartUpload, NoncurrentVersionExpiration, and ExpiredObjectDeleteMarker and NoncurrentDays vervalt na 7 dagen.
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-lifecycle --bucket s3_bkt --lifecycle-configuration file://s3_bkt_lifecycle.json
Output:
{
"Rules": [
{
"ID": "expire-non-current-and-dmarkers-and-mpu",
"Status": "Enabled",
"Prefix": "/",
"Expiration": {
"ExpiredObjectDeleteMarker": true
},
"AbortIncompleteMultipartUpload": {
"DaysAfterInitiation": 7
},
"NoncurrentVersionExpiration": {
"NoncurrentDays": 7
}
}
]
}
- GET levenscyclusbeleid
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-lifecycle --bucket s3_bkt
Output:
{
"Rules": [
{
"Expiration": {
"Days": 10
},
"ID": "DeleteVersion-musa",
"Prefix": "",
"Status": "Enabled",
"NoncurrentVersionExpiration": {
"NoncurrentDays": 10
}
}
]
}
- Objecttagging met behulp van sleutelwaardepaar
- Schrijf een bestand.
$ aws s3 cp file.txt s3://mc_s3_bkt/aws/tag.txt --profile mc_s3_emea --endpoint http://emea:9020
upload: ./file.txt to s3://mc_s3_bkt/aws/tag.txt
- Add tag (deze opdracht heeft geen uitvoer indien succesvol.
Eenregelige opdracht:
$ aws s3api put-object-tagging --profile mc_s3_emea --bucket mc_s3_bkt --key aws/tag.txt --tagging '{"TagSet": [{ "Key": "Product", "Value": "ECS" }]}' --endpoint-url http://emea:9020
Kopiëren en plakken van meerdere regels:
$ aws s3api put-object-tagging \
--profile mc_s3_emea \
--bucket mc_s3_bkt \
--key aws/tag.txt \
--tagging '{"TagSet": [{ "Key": "Product", "Value": "ECS" }]}' \
--endpoint-url http://emea:9020
- Haal de objecttag op.
$ aws s3api get-object-tagging --profile mc_s3_emea --bucket mc_s3_bkt --key aws/tag.txt --endpoint http://emea:9020
{
"TagSet": [
{
"Key": "Product",
"Value": "ECS"
}
]
}
- Adding multiple tags values '
key:value' - korte vorm
$ aws s3api put-object-tagging --profile mc_s3_emea --bucket mc_s3_bkt --key aws/tag5.txt --tagging '{"TagSet": [{ "Key": "Product", "Value": "ECS 3.6.1.2" },{"Key": "Company", "Value": "Dell Technologies"}]}' --endpoint-url http://emea:9020
- Haal de objecttag op.
$ aws s3api get-object-tagging --profile mc_s3_emea --bucket mc_s3_bkt --key aws/tag5.txt
{
"TagSet": [
{
"Key": "Product",
"Value": "ECS 3.6.1.2"
},
{
"Key": "Company",
"Value": "Dell Technologies"
}
]
}
- S3-objectvergrendeling
- De ECS S3 objectvergrendelingsfunctie ondersteunt alleen buckets waarvoor versiebeheer is ingeschakeld.
- Er is geen ECS-gebruikersinterface voor Object Lock. Het kan worden geopend via ECS Object Lock API's.
- De vergrendelde objecten zijn beschermd tegen levenscyclusverwijderingen
- Bucket kan niet worden ingeschakeld Bestandssysteem
- Objectvergrendeling werkt met IAM-gebruikers en niet met oudere gebruikers
- Objectvergrendeling op de bucket inschakelen, automatisch versiebeheer inschakelen
- Een patch is vereist als ADO is ingeschakeld en moet worden aangepakt in ECS 3.7. Zie artikel ECS: Objectvergrendelingsfunctie uitschakelen op ECS voor IBM Content Manager
Om een objectvergrendeling op een bucket in te stellen.
De optie use put-object-lock-configuration wordt gebruikt met AWS CLI.
Zie: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html
put-object-lock-configuration — AWS CLI 1.22.24 Command Reference (amazon.com) (External Link)
- Een objectvergrendelingsconfiguratie instellen voor een bucket
The following put-object-lock-configuration example sets a 1-day object lock on the specified bucket.
$ aws s3api put-object-lock-configuration \
--profile iam1 \
--bucket iam-bucket \
--object-lock-configuration '{ "ObjectLockEnabled": "Enabled", "Rule": { "DefaultRetention": { "Mode": "COMPLIANCE", "Days": 1 }}}'
Deze opdracht produceert geen uitvoer.
put-object-legal-hold
$ aws s3api put-object-legal-hold --endpoint http://<hostname>:<port_number> --profile iam1 --bucket iam-bucket --key file1.txt --legal-hold "Status=ON" where: --profile: name of profile is profile confirmed in .aws credentials file --bucket: Bucket name --key: Object name --legal-hold: ON or OFF --version-id: specifies the version id of the object for Versioned --endpoint: ECS IP and port 9020 or 90201
get-object-legal-hold
$ aws s3api get-object-legal-hold --endpoint http://<hostname>:<port_number> --profile iam1 --bucket iam-bucket --key file1.txt where: --bucket: Bucket name --key: Object name --version-id: specifies the version id of the object --endpoint: ECS IP and port 9020 or 90201