ECS: S3 AWS CLI'yi Yapılandırma ve Kullanma
Summary: İşlevselliği ve uyumluluğu doğrulamak için ECS ile AWS CLI'yı kullandıkları müşteri senaryolarını test etmek için AWS CLI'yı kullanırken ECS AWS S3 tarafından desteklenen API çağrıları için her zaman ECS Veri Erişim Kılavuzu'na başvurun. ...
Instructions
AWS Komut Satırı Arabirimi (AWS CLI), S3 üst düzey komutlarını test etmek için kullanılabilen bir AWS aracıdır ve s3 API Düzeyinde (s3api)
Yüksek düzey, aws s3 (Harici Bağlantı) komutları, grup oluşturma, listeleme ve silme gibi yaygın klasör işlemlerini destekler. Araç nasıl indirilir ve kurulur, desteklenen tüm Üst Düzey komutlar, komut kullanılarak komut kümesinden edinilebilir aws s3api help'dir.
S3Uri: Bir S3 nesnesinin, ön ekinin veya grubun konumunu temsil eder: Bu, forma yazılmalıdır s3://mybucket/mykey nerede mybucket S3 grubu belirtildi, mykey belirtilen S3 anahtarıdır. Yol bağımsız değişkeni ile başlamalıdır s3://
API Düzeyinde aws s3api (Harici Bağlantı) komutları, s3api övgü kümesinde yer alır. Bu S3 API komutları, klasör ACL, klasör politikası ve yaşam döngüsü politikaları gibi klasör meta verilerine erişim sağlar. Desteklenen tüm API çağrıları, komut kullanılarak komut kümesinden alınabilir aws s3api help.
- AWS CLI, varsayılan olarak yüklemeler sırasında dosya veya parça yüklemek için otomatik olarak 10 adede kadar iş parçacığı kullanır
- AWS CLI, dosyalar >için otomatik olarak multipart_threshold yüklemesi kullanır = 8 MB dosya boyutu, multipart_chunksize
İndirme ve yükleme talimatları.
- Sürüm sürümleri https://github.com/aws/aws-cli/releases (Harici Bağlantı)
- AWS CLI paketini indirme ve yükleme
# curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
- Paketi ayıkla
# unzip awscli-bundle.zip
- Yükleme komutunu çalıştırın
# sudo /awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
- Sürümü onayla
# aws version
Output: aws-cli/2.0.33 Python/3.7.3 Linux/4.15.0-109-generic botocore/2.0.0dev37
AWS CLI'yı yapılandırma
Bu bölümde, ECS nesne kullanıcısı kullanarak AWS CLI'yı ECS S3 ile kullanmak üzere yapılandırmanın temel adımları açıklanmaktadır. Bu bölüm, Grup ve nesne kullanıcısının ECS'de zaten oluşturulduğunu varsayar. Kimlik bilgileri ve yapılandırma dosyası, komutu çalıştırdığınızda güncelleniraws configure'dir.
Kimlik bilgileri dosyası burada bulunur
~/.aws/credentials. Kimlik bilgileri dosyası, kullanıcı profili ayrıntılarını (Erişim anahtarı kimliği ve Gizli erişim Anahtarları) depolar, yapılandırma dosyası bölge ve çıktı biçimi ayrıntılarını depolar.
Gerekli:
- Erişim anahtarı kimliği: ECS nesne kullanıcısı
- Gizli Erişim anahtarı: Secret Key
- Bu örnek bir profil adı oluşturur 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
- Liste profilleri, tüm profiller (AWS CLI v2'de bulunan liste özellikleri)
# 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
- Listeye özel 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))
- 9021'de komut kullanıyorsanız, AWS CLI seçeneği
--no-verify-sslKendinden imzalı sertifika hatasını atlamak için gereklidir.
# 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)
- Komutu şununla çalıştırın:
--no-verifyBu hatayı atlama seçeneği
# 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
- İkinci seçenek, PEM biçiminde kaydedilmiş ECS kendinden imzalı sertifikasını indirmek ve
--ca-bundleseçenek - Bağlantı noktası 9021'de nesne veri erişimi için ECS sertifikası almak üzere OpenSSL'yi kullanın ve aşağıdaki örneğe göre favori düzenleyicinizi kullanarak sertifika içeriğini kopyalayın ve sertifika başlıkları dahil olmak üzere kaydedin.
# openssl s_client -connect ecshop:9021
ecshop ECS düğümleri IP'si veya ana bilgisayar adıdır ve xxxxxx ortamınızdaki sertifikanın tamamı olmalıdır.
Output: -----BEGIN CERTIFICATE----- Xxxxxxxxx xxxxxxxxx ... ... -----END CERTIFICATE-----
- Sertifikanın PEM dosya adı ecshop_cert_pem içinde kaydedildiği ca-bundle seçeneğiyle grup bilgilerini tabloda listeleyin
# 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 || |+-----------------------------------+---------------------+|
Temel S3 işlemleri
https://docs.aws.amazon.com/cli/latest/userguide/cli-services-s3-commands.html (Harici Bağlantı)Performans ayarı
- max_concurrent_requests - Maksimum eşzamanlı istek sayısı
- max_queue_size - Görev kuyruğundaki en fazla görev sayısı
- multipart_threshold - CLI'nın bağımsız dosyaların çok parçalı aktarımları için kullandığı boyut eşiği.
- multipart_chunksize - Çok parçalı aktarımlar kullanılırken bu, CLI'nın dosyaların çok parçalı aktarımları için kullandığı öbek boyutudur.
- max_bandwidth - Amazon S3'e veri yüklemek ve Amazon S3'ten veri indirmek için kullanılan maksimum bant genişliği.
# 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 = autoKullanıcı arayüzü uygulamalarını başlatmak için
aws configure set Yükleme hızlarını ayarlamak için parametreleri ayarlama komutu
$ 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 autoAdımlar:
- Create bucket using
s3 mbkomut
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 mb s3://s3_bkt
Output:
make_bucket: s3_bkt
- Şu komutu kullanarak grupları listele:
s3 lsves3api list-bucketskomut kümeleri, bir gruptaki diğer işlemler (S3'te "önekler" olarak adlandırılır) (Harici Bağlantı) için grupları listeler
# 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"
},
- Test için dosya oluşturma ve yükleme
- 1 MB ve 4 MB dosya oluşturma örneği
# dd if=/dev/zero of=1MB_output.file bs=1024 count=1024 # dd if=/dev/zero of=4MB_output.file bs=1024 count=4096
- 2 GB büyük dosya oluşturma örneği
# dd if=/dev/urandom of=bigfile_2GB bs=1024k count=2048
- Kovaya 1 MB dosya yükleyin
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
- Kovadaki dosyaları listeleyin,
s3_bktProfil adını kullanma mc_s3 kullanmas3 lsveyas3api list-objectsKomut kümeleri
# 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" } },
- Nesne sürümlerini listeleme
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api list-object-versions --bucket s3_bkt --output text
- Dosyayı indir, 1MB_output.file
s3_bktyerel makinede /tmp dizinine.
# 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
- Okunabilirlik çıktısı için YAML biçimindeki bir dosya 1MB_output.file'nin ACL'sini kontrol edin
# 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
- Kovadaki kova ACL'sini kontrol etme
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
- Kova sürümünü kontrol edin veya kovada sürüm oluşturmayı etkinleştirin
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output:
{
"Status": "Enabled"
}
- Büyük bir dosyayla s3api API düzeyini kullanarak çok parçalı yükleme başlatma
- 5 GB'lık bir dosya oluşturun:
# time dd if=/dev/urandom of=bigfile_5GB bs=1024k count=5096
- Yüklemeyi başlat
# 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"
}
- Tamamlanmamış çok parçalı dosya yüklemelerini listeleme https://aws.amazon.com/premiumsupport/knowledge-center/s3-multipart-upload-cli/ (Harici Bağlantı)
# 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"
}
}
]
}
- İlerletmek
s3 cpÇok parçalı yüklemeleri başlatmak ve eş zamanlı iş parçacıklarını değiştirmek üzere büyük dosyalar için komut veya kovadan kovaya performans önerileri, yukarıdaki Performans Ayarı bölümüne bakın.
- file.txt kopyalamak için kovadan kovaya kopyalama işlemi gerçekleştirin
mc_s3_bktözniteliğinin değerinis3_bktS3api kullanma
# 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"
}
}
- Bir kovadaki dosyaları (nesneleri veya anahtarları) listeleme
# 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
- Bir dosyayı şuradan kopyalama
S3_bktözniteliğinin değerinimc_s3_bktS3 CP üst düzey komut kümesini kullanma
# 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
- Bucket da sürüm oluşturmanın etkin olup olmadığını kontrol etme
s3_bkt
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api get-bucket-versioning --bucket s3_bkt
Output:
{
"Status": "Enabled"
}
- Şu komutu kullanarak grubu silin:
s3 rbkomut (komutun çıktısı yok)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3 rm s3://s3_bkt2
- Aşağıdaki örnek, kovadaki tüm nesneleri ve alt klasörleri siler ve ardından kovayı kaldırır. (sürüm oluşturma etkinse, bu komut sürüm nesnelerini kaldırmaz (LDS, Yaşam döngüsü politikalarını gözden geçirin)
# aws s3 rb s3://bucket-name --force
- Enable versioning on bucket
s3_bktusing s3api API level command set (komutun çıktısı yok)
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-versioning --bucket s3_bkt --versioning-configuration Status=Enabled
- Yaşam döngüsü politikası uygulama Şablon oluşturma (ECS Veri Erişimi rehberine başvurun) AWS CLI, yaşam döngüsü politikası için json biçimi gerektirir
# aws --profile mc_s3 --endpoint http://ecshop:9020 s3api put-bucket-lifecycle-configuration --generate-cli-skeleton input --bucket s3_bkt
- Kovaya kova ömrü politikası uygulayın. Daha fazla ayrıntı için ECS Veri Erişim Rehberi'ne bakın
AbortIncompleteMultipartUpload, NoncurrentVersionExpiration, and ExpiredObjectDeleteMarker and NoncurrentDays 7 gün sonra sona erecek.
# 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 yaşam döngüsü politikası
# 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
}
}
]
}
- Anahtar değer çifti kullanarak nesne etiketleme
- Bir dosya yazın.
$ 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 (bu komut başarılı olursa çıktı vermez.
Tek satırlık komut:
$ 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
Çok satırlı kopyalama ve yapıştırma:
$ 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
- Nesne etiketini alır.
$ 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"
}
]
}
- Birden çok etiket değeri ekleme ›
key:value' - kısa biçim
$ 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
- Nesne etiketini alır.
$ 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 Object Lock
- ECS S3 Nesne Kilidi özelliği yalnızca sürüm oluşturmanın etkinleştirildiği grupları destekler.
- Object Lock için ECS kullanıcı arayüzü yoktur. ECS Nesne Kilidi API'leri aracılığıyla erişilebilir.
- Kilitli nesneler, yaşam döngüsü silmelerine karşı korunur
- Kova, Dosya sistemi etkin olamaz
- Nesne kilidi, eski kullanıcılarla değil IAM kullanıcılarıyla çalışır
- Kovada nesne kilidini etkinleştirme, sürüm oluşturmayı otomatik olarak etkinleştirme
- ADO etkinse ve ECS 3.7'de ele alınacaksa bir yama gereklidir. ECS makalesine bakın: IBM Content Manager için ECS de Nesne kilidi özelliğini devre dışı bırakma
Bir kovada nesne kilidi ayarlamak için.
Use put-object-lock-configuration seçeneği AWS CLI ile birlikte kullanılır.
Bkz.: https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html
put-object-lock-configuration — AWS CLI 1.22.24 Komut Referansı (amazon.com) (Harici Bağlantı)
- Bir kovada nesne kilidi yapılandırması ayarlamak için
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 }}}'
Bu komut hiçbir çıktı üretmez.
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