中野智文のブログ

データ・マエショリストのメモ

numpy array を aws s3 に格納する。

背景

jupyter notebook を使っていて、データをローカルのファイルシステムに保存するようにしていると、 環境が変わったときにそのデータまで一緒に持ってこないといけないが、これは jupyter の利便性を失う一つの要因となる。 例えば github でjupyter notebook を管理する場合、ローカルにあるデータのファイルまで github 上に格納しなければならない。 google Colaboratory を使う場合、クラウド上で実行されるので、そのローカルにはデータは存在しない。

長々と書いてしまったが、要は、クラウド上に保存し、クラウドからローカルに落とせばよいのである。

あまり単純な例がない、numpy array を aws s3 に格納する例を書いておきたい。

numpy array を aws s3 に save し、load する例

import os
import boto3

os.environ["AWS_ACCESS_KEY_ID"] = "AAAAAAAAAAAAAAA"
os.environ["AWS_SECRET_ACCESS_KEY"] = "XXXXXXXXXXXXXXXXXXXXXXX"

s3 = boto3.resource('s3')
# 書き込み

import numpy as np
import tempfile

a = np.array([1,2,3,4,5,6])

with tempfile.TemporaryFile() as temp:
  np.save(temp, a)
  temp.seek(0)
  res = s3.Object(bucket_name="your-bucket", key="aaa.npy").upload_fileobj(temp)
# 読み込み

import tempfile

with tempfile.TemporaryFile() as temp:
  res = s3.Object(bucket_name="your-bucket", key="aaa.npy").download_fileobj(temp)
  temp.seek(0)
  aa = np.load(temp)

temp.seek(0)temp ファイルオブジェクトに書き込まれたデータを先頭から読み直すために、rewind している。 Webをみると、boto3 でなく boto を使った方法などいろいろ紹介されているが boto を使った方法はうまく動かなかった。 ちなみに、上記は、google colaboratory を使って確認した。

まとまりが悪いが、これにて。

Windows 用 github ツールにて、the repository does not seem to exist anymore

背景

Windowsgithub ツールで、次のようなエラーが出た。

the repository does not seem to exist anymore you may not have access or it may have been deleted or renamed

もちろん、そのようなリポジトリは実際存在する。

なぜか?

原因と解決

自分の場合は、github の権限の設定忘れだった。

チームの以下の設定を、

Repository permissions

Choose default permissions for user roles.
Organization members

を ”Wrie” 以上に設定する。

Windows10 に WSL を入れようとして、The term 'Enable-WindowsOptionalFeature' is not recognized …

背景

Windows 10 に WSL を入れようとして、

PS C:\Program Files\PowerShell\6.0.2> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature : The term 'Enable-WindowsOptionalFeature' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Enable-WindowsOptionalFeature:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

みたいなエラーが出たあなた。

www.atmarkit.co.jp

や、

Windows Subsystem for Linux - Wikipedia

の通りに正しくやったのに。納得がいかない。

解決法

Windowsの機能の有効化または無効化」の中から、「Windows Subsystem for Linux」にチェックを入れて、再起動。

で、「Windowsの機能の有効化または無効化」は「コントロールパネル」にあるらしいのだが、その「コントロールパネル」が見つからなかったりするのはお約束。

東京以外のおすすめAWSリージョン

背景

東京リージョンは応答時間は早いけど、応答時間がどうでもいいなら、もっと安いリージョンがいい。 もう少し欲を言うと、AWSの最新のサービスが利用できるところがいい。 さらに欲を言うと、それでも応答時間が早いほうがいい。

リージョン比較

安いリージョン

qiita.com

によると、安いのは、us-east-1(ヴァージニア)か、us-west-2(オレゴン)だそうで。 ただちょっと古いのが気になる。us-east-2(オハイオ)も安い気がする。

最新技術

現時点で SageMaker が使える

現時点で Fargate が使える

https://aws.amazon.com/jp/about-aws/whats-new/2018/03/aws-fargate-platform-version-1-1/

その他

https://aws.amazon.com/jp/about-aws/global-infrastructure/regional-product-services/

たまにオレゴンしかないものものあるが、ヴァージニア優勢な感じ。

応答時間

qiita.com

地図上では西海岸の方が近いイメージだけど、そうらしい。

まとめ

us-east-1(バージニア北部)を使おう。

Windows PowerShell の OpenSSH でパスワードを正しく入れてもログインできない。

背景

Windows PowerShell の OpenSSH でパスワードを正しく入れてもログインできない。

原因

-v オプションをつけることで原因を見つけることができた。

read_passphrase: can't open /dev/tty: No such file or directory

入力を ' /dev/tty' から取ろうとしているけど、Windowsにそんなものはない。

~/.ssh/id_rsa.pub などを転送してやれば、パスワード入力が省略でき回避できるかもしれない。 でもそれって、結局 scp でパスワード聞かれることだよね?

issue には上がっている。

github.com

最新版で解決したの? いえ、解決していないでしょ。

WSLを入れることにしたのでした。

参考

github.com

AWSのMFAが灰色で有効にできない→一応解決

背景

AWSの「MFAの管理」が灰色で有効にできない。なぜなのか?

解決

灰色で有効にできない謎は未解決だが、一応できたのでメモ。

同じページのIAM リソース のユーザーをクリック。 自分の名前を見つけ出しクリック。 認証情報のタブをクリック。 すると、MFA デバイスの割り当てというところの右側に鉛筆のアイコンがあるのでクリック。

あとは通常のMFAの割り当てと同じ。

何か設定がおかしいのだろうけど、とりあえずできた。