ECS: Sådan konfigureres og bruges S3 AWS CLI

Summary: Når AWS CLI bruges til at teste kundescenarier, hvor de bruger AWS CLI med ECS til at bekræfte funktionalitet og kompatibilitet, skal du altid se ECS Data Access Guide for ECS AWS S3-understøttede API-kald. ...

This article applies to This article does not apply to This article is not tied to any specific product. Not all product versions are identified in this article.

Instructions

AWS Command-Line Interface (AWS CLI) er et værktøj fra AWS, der kan bruges til at teste S3-kommandoer på højt niveau og s3 API-niveau (s3api) AWS s3-kommandoer (eksternt link)

på højt niveau understøtter almindelige bucket-handlinger, såsom oprettelse, notering og sletning af buckets. Sådan downloades og installeres værktøjet, alle understøttede kommandoer på højt niveau kan fås i kommandosæt ved hjælp af kommandoen aws s3api help.

S3Uri: Repræsenterer placeringen af et S3-objekt, præfiks eller bucket - Dette skal skrives i formularen s3://mybucket/mykey hvor mybucket er t specificeret S3 spand, mykey er den angivne S3-tast. Stiargumentet skal begynde med s3://

AWS s3api-kommandoer (eksternt link) på API-niveau er indeholdt i s3api-anbefalingssættet. Disse S3 API-kommandoer giver adgang til bucket-metadata, som bucket ACL, bucket policy, livscykluspolitikker for at nævne nogle få, alle understøttede API-kald kan hentes i kommandosæt ved hjælp af kommando aws s3api help.

  • AWS CLI bruger automatisk op til 10 tråde til at uploade filer eller dele under uploads som standard
  • AWS CLI bruger automatisk multipart_threshold uploads til filer >= 8 MB filstørrelse multipart_chunksize

Download og installer vejledninger.

  1. Version udgivelser https://github.com/aws/aws-cli/releases (Eksternt link)
  2. Download og installer AWS CLI-pakken
# curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
  1. Udpak bundt
# unzip awscli-bundle.zip
  1. Kør installationskommando
# sudo /awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
  1. Bekræft version
# aws version
Output:
      aws-cli/2.0.33 Python/3.7.3 Linux/4.15.0-109-generic botocore/2.0.0dev37

Konfiguration af AWS CLI

Dette afsnit forklarer de grundlæggende trin til konfiguration af AWS CLI til brug med ECS S3 ved hjælp af ECS-objektbruger. Dette afsnit forudsætter, at Bucket og objektbrugeren allerede er oprettet på ECS. Legitimationsoplysningerne og konfigurationsfilen opdateres, når du kører kommandoen aws configure.

Legitimationsoplysningsfilen findes her ~/.aws/credentials. Legitimationsoplysninger fil gemmer brugerprofil detaljer (adgangsnøgle id og hemmelige adgangsnøgler) konfiguration fil gemmer region og output format detaljer.

Kræves:
  • Adgangsnøgle-id: ECS-objektbruger
  • Hemmelig adgangsnøgle: Hemmelig nøgle
Trin:
  1. Dette eksempel opretter et profilnavn 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
  1. Vis profiler alle profiler (listeegenskaber tilgængelige i 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
  1. Listespecifik profil
# 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))
  1. Hvis du bruger kommandoer på 9021, AWS CLI-indstilling --no-verify-ssl er påkrævet for at omgå fejlen med det selvsignerede certifikat.
# 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)
  • Kør kommando med --no-verify Mulighed for at omgå denne fejl
# 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
  • Den anden mulighed ville være at downloade ECS selvsigneret certifikat gemt i PEM-format og ved hjælp af --ca-bundle valgmulighed
  • Brug OpenSSL til at få ECS-certifikat til adgang til objektdata på port 9021, og kopier certifikatindhold ved hjælp af din foretrukne editor, og gem inklusive certifikatoverskrifter i eksemplet nedenfor.
# openssl s_client -connect ecshop:9021
Hvor ecshop er ECS-nodens IP eller værtsnavn, og xxxxxx skal være hele certifikatet i dit miljø.
Output:

    -----BEGIN CERTIFICATE----- 
    Xxxxxxxxx
    xxxxxxxxx
    ...
    ...
    -----END CERTIFICATE-----
  1. Liste over buckets i tabel Miljøvenlig med mulighed for ca-bundt, hvor certifikatet gemmes i PEM-filnavnet 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              ||
    |+-----------------------------------+---------------------+|

Grundlæggende S3-betjening

https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html (Eksternt link)
Justering af ydeevne
  • max_concurrent_requests – Det maksimale antal samtidige anmodninger
  • max_queue_size – Det maksimale antal opgaver i opgavekøen
  • multipart_threshold – Den størrelsestærskel, som CLI bruger til overførsel af individuelle filer i flere dele.
  • multipart_chunksize – Når du bruger overførsler i flere dele, er dette den blokstørrelse, som CLI bruger til overførsler af individuelle filer i flere dele.
  • max_bandwidth - Den maksimale båndbredde, der forbruges til upload og download af data til og fra Amazon S3.
Gemt i konfigurationsfilen som et eksempel:
# 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 = auto 
Bruge aws configure set kommando til at indstille parametre for at indstille uploadhastigheder
$ 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 auto
Trin: 
  1. Opret bucket ved hjælp af s3 mb kommando
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 mb s3://s3_bkt
Output:
    make_bucket: s3_bkt
  1. Liste buckets ved hjælp af s3 ls og s3api list-buckets Kommandosæt viser buckets til alle andre operationer (i S3 benævnt 'præfikser') (eksternt link) i en 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"
			},
  1.  Oprettelse og upload af filer til test 
  • Eksempel på oprettelse af filer på 1 MB og 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
  • Eksempel på oprettelse af en stor fil på 2 GB
# dd if=/dev/urandom of=bigfile_2GB bs=1024k count=2048
  • Upload 1MB fil til 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
  1. Liste filer i spand, s3_bkt Brug af profilnavn mc_s3 brug af s3 lseller s3api list-objects Kommandosæt 
# 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"
				}
			},
  1. Vis objektversioner
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-object-versions --bucket s3_bkt --output text
  1. Download fil, 1MB_output.fil fra s3_bkt til mappen /tmp på den lokale maskine.
# 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
  1. Kontroller ACL for en fil 1MB_output.file i YAML-format for output for læsbarhed
# 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
  1. Kontroller skovlen ACL på spanden 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
  1. Kontrollér bucket-versionen, eller aktivér versionering på bucket
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output:

    {
        "Status": "Enabled"
    }
  1. Start upload af flere dele ved hjælp af s3api API-niveau med en stor fil 
  1. Opret en 5 GB fil:
# time dd if=/dev/urandom of=bigfile_5GB bs=1024k count=5096
  1. Start overførsel
# 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"
    }
  1. Vis ufuldstændige filoverførsler i flere dele https://aws.amazon.com/premiumsupport/knowledge-center/s3-multipart-upload-cli/ (Eksternt 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"
	            }
	        }
	    ]
	}
  1. Forbedre s3 cp Kommando eller bucket for at gøre bucket til bucket ydeevne anbefalinger for store filer for at starte flerdelte uploads og ændring af samtidige tråde, se ovenfor under Performance tuning.
  1. Udfør bucket to bucket-kopi for at kopiere file.txt i mc_s3_bkt til s3_bkt brug af 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"
    }
}
  1. Liste filer (objekter eller nøgler) i en bucket 
# 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
  1. Kopiering af en fil fra S3_bkt til mc_s3_bkt Brug af S3 CP-kommandosæt på højt niveau
Følgende cp-kommando kopierer et enkelt s3-objekt til en specificeret bucket og nøgle:
# 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
  1. Kontrollér, om versionsstyring er aktiveret på bucket s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output: 

      {
          "Status": "Enabled"
      }
  1. Slet bucket ved hjælp af s3 rb kommando (kommandoen har intet output)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 rm s3://s3_bkt2
  1. I følgende eksempel slettes alle objekter og undermapper i bucket'en, og derefter fjernes bucket'en. (hvis versionsstyring er aktiveret, fjerner denne kommando ikke versionsobjekter (gennemgå LDS, livscykluspolitikker)
# aws s3 rb s3://bucket-name --force
  1. Aktivér versionsstyring på bucket s3_bkt ved hjælp af kommandosættet på API-niveau for s3API (kommandoen har ikke output)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-versioning --bucket s3_bkt --versioning-configuration Status=Enabled 
  1. Anvendelse af livscykluspolitik Generer skabelon (Se vejledningen til ECS-dataadgang) AWS CLI kræver json-format til livscykluspolitik
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-lifecycle-configuration --generate-cli-skeleton input --bucket s3_bkt
  1. Anvend bucket life-politik på skovl. Du kan finde flere oplysninger i ECS Data Access Guide
Opret politik for AbortIncompleteMultipartUpload, NoncurrentVersionExpiration, and ExpiredObjectDeleteMarker and NoncurrentDays udløber efter 7 dage.
#  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
      }
   }
   ]
}
  1. GET-livscykluspolitik
# 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
            }
        }
    ]
}
  1. Objektkodning ved hjælp af nøgleværdipar 
  1. Skriv en fil. 
$ 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
  1. Tilføj kode (denne kommando har ikke outputtet, hvis den lykkes. 
    Kommando på én linje:
$ 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

Kopier og indsæt med flere linjer: 

$ 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
  1. Hent objektmærket.
$ 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"
        }
    ]
}
  1. Tilføjelse af flere tags værdier 'key:value' - kort form
$ 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
  1. Hent objektmærket.
$ 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"
        }
    ]
}
  1. S3-objektlås
ECS giver dig mulighed for at gemme objekter ved hjælp af en WORM-model (write-once-read-many) via S3-objektlås. Denne funktion forhindrer, at objekter slettes eller overskrives i et bestemt tidsrum eller på ubestemt tid.
 
Bemærk:
  • ECS S3-objektlåsfunktionen understøtter kun versionsstyringsaktiverede buckets.
  • Der er ingen ECS-brugergrænseflade til Object Lock. Den kan tilgås via ECS Object Lock API'er.
  • De låste objekter er beskyttet mod sletning af livscyklus
  • Bucket kan ikke være Filsystem aktiveret
  • Objektlås fungerer med IAM-brugere og ikke ældre brugere 
  • Aktivering af objektlås på skovlen, aktivering af versionsstyring automatisk 
  • En programrettelse er påkrævet, hvis ADO er aktiveret, og som skal behandles i ECS 3.7. Se artiklen ECS: Deaktivering af funktionen Objektlås på ECS til IBM Content Manager


Sådan indstilles en objektlås på en bucket.
Brug indstillingen put-object-lock-configuration bruges sammen med AWS CLI.

Se: 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) (Eksternt link)

  • Sådan indstilles en objektlåskonfiguration på en 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 }}}'

Denne kommando giver intet output.

  • 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

Affected Products

Elastic Cloud Storage

Products

ECS Appliance, ECS Appliance Hardware Series, ECS Appliance Software with Encryption, Elastic Cloud Storage
Article Properties
Article Number: 000020564
Article Type: How To
Last Modified: 02 Oct 2025
Version:  6
Find answers to your questions from other Dell users
Support Services
Check if your device is covered by Support Services.