5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ドット付きのS3バケットからGCSへファイルコピーをする方法

Posted at

通常、S3からGCSへのファイル移動する時には、両方のアクセスキー設定を行い
gsutilコマンドを使うことで転送ができるが、S3のバケット名に. が入っているとエラーになってしまう。

結論

AWS側の設定は $HOME/.boto に記述する。
必要最低限の項目は以下のもの。

$HOME/.boto
[Credentials]
aws_access_key_id = <AWSのアクセスキー>
aws_secret_access_key = <AWSのシークレットキー>

s3_host = s3-ap-northeast-1.amazonaws.com

[Boto]
https_validate_certificates = False

[s3]
calling_format = boto.s3.connection.OrdinaryCallingFormat

以下調査メモ

S3のバケット hoge.fuga から、GCSへファイル転送をする時。

アクセスキー情報を入れただけの時

設定ファイル

$HOME/.boto
[Credentials]
aws_access_key_id = <AWSのアクセスキー>
aws_secret_access_key = <AWSのシークレットキー>

実行結果

$ gsutil ls s3://hoge.fuga/sample.txt
Failure: Host hoge.fuga.s3.amazonaws.com returned an invalid certificate (remote hostname "hoge.fuga.s3.amazonaws.com" does not match certificate): {'crlDistributionPoints': (u'http://crl3.digicert.com/DigiCertBaltimoreCA-2G2.crl', u'http://crl4.digicert.com/DigiCertBaltimoreCA-2G2.crl'), 'subjectAltName': (('DNS', '*.s3.amazonaws.com'), ('DNS', 's3.amazonaws.com')), 'notBefore': u'Sep 22 00:00:00 2017 GMT', 'caIssuers': (u'http://cacerts.digicert.com/DigiCertBaltimoreCA-2G2.crt',), 'OCSP': (u'http://ocsp.digicert.com',), 'serialNumber': u'0551B592FA53CF2052B8B70F275CC159', 'notAfter': 'Jan  3 12:00:00 2019 GMT', 'version': 3L, 'subject': ((('countryName', u'US'),), (('stateOrProvinceName', u'Washington'),), (('localityName', u'Seattle'),), (('organizationName', u'Amazon.com Inc.'),), (('commonName', u'*.s3.amazonaws.com'),)), 'issuer': ((('countryName', u'US'),), (('organizationName', u'DigiCert Inc'),), (('organizationalUnitName', u'www.digicert.com'),), (('commonName', u'DigiCert Baltimore CA-2 G2'),))}.

参考にしたサイト

ドット(.)を含むS3バケットへgsutilからアクセスする

https_validate_certificatesの設定を追加する

設定ファイル

$HOME/.boto
[Credentials]
aws_access_key_id = <AWSのアクセスキー>
aws_secret_access_key = <AWSのシークレットキー>

[Boto]
https_validate_certificates = False

実行結果

gsutil ls s3://hoge.fuga/sample.txt
Failure: hostname u'hoge.fuga.s3.amazonaws.com' doesn't match either of '*.s3.amazonaws.com', 's3.amazonaws.com'.

参考にしたサイト

python - Can't connect to S3 buckets with periods in their name, when using Boto on Heroku - Stack Overflow

calling_formatの設定を追加する

設定ファイル

$HOME/.boto
[Credentials]
aws_access_key_id = <AWSのアクセスキー>
aws_secret_access_key = <AWSのシークレットキー>

[Boto]
https_validate_certificates = False

[s3]
calling_format = boto.s3.connection.OrdinaryCallingFormat

実行結果

$ gsutil ls s3://hoge.fuga/sample.txt
ServiceException: 301

参考サイト

Can't use bucket names with dots · Issue #2836 · boto/boto · GitHub

s3_hostを追加する

設定ファイル

$HOME/.boto
[Credentials]
aws_access_key_id = <AWSのアクセスキー>
aws_secret_access_key = <AWSのシークレットキー>

s3_host = s3-ap-northeast-1.amazonaws.com

[Boto]
https_validate_certificates = False

[s3]
calling_format = boto.s3.connection.OrdinaryCallingFormat

実行結果

$ gsutil ls s3://hoge.fuga/sample.txt
s3://hoge.fuga/sample.txt

みれた。s3からgcsへのコピーもできた。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?