過去にQiitaに投稿した内容のアーカイブです。
LangChainのクイックスタートガイドを日本語に翻訳しながらやってみました。
実行結果も記載しますので、これを読んだらクイックスタートをやった気になれます
過去にQiitaに投稿した内容のアーカイブです。
LangChainのクイックスタートガイドを日本語に翻訳しながらやってみました。
実行結果も記載しますので、これを読んだらクイックスタートをやった気になれます
過去にQiitaに投稿した内容のアーカイブです。
Ubuntu 20.04のPythonのバージョンは3.8です。 事情があってPython 3.7が必要だったので、ソースからビルドしてインストールしてみました。
sudo apt install build-essential -y
sudo apt install libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev -y
sudo apt install libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev uuid-dev -y
wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz
tar zxvf Python-3.7.10.tgz
cd Python-3.7.10/
./configure --enable-optimizations
make -j4
sudo make altinstall
過去にQiitaに投稿した内容のアーカイブです。
AWS IoTのフリートプロビジョニング機能が面白そうだなぁと思ってAWS IoT Device SDK for PythonのGitHubのREADMEを眺めていると ## New Version Available の文字が!!!
AWS IoT SDK for Python v2が出てました。
https://github.com/aws/aws-iot-device-sdk-python-v2
(呼び方はAWS IoT SDK for Python v2なのかaws-iot-device-sdk-python-v2なのかAWS IoT Client SDK for Pythonなのかよくわかりません)
READMEによると
This SDK is built on the AWS Common Runtime, a collection of libraries written in C to be cross-platform, high-performance, secure, and reliable.
だそうです。
さらにv2はフリートプロビジョニングのAPIにもすでに対応しており、サンプルも含まれています。 今後はv2が主流でしょうか。
AWSのブログで紹介されていたサンプルと同じ内容をv2で試してみました。
フリートプロビジョニングを用いて、IoTデバイスとAWS IoT Coreの初期セットアップを自動化する方法
Mac Python 3.8.2
git clone https://github.com/aws/aws-iot-device-sdk-python-v2.git
pip install ./aws-iot-device-sdk-python-v2
証明書は以下の場所に配置しました。
.
├── aws-iot-device-sdk-python-v2
└── certs
├── bootstrap-certificate.pem.crt
├── bootstrap-private.pem.key
└── root.ca.pem
templateNameやtemplateParametersはいい感じに修正ください。
cd aws-iot-device-sdk-python-v2/samples/
python fleetprovisioning.py \
--endpoint xxxxxxxxxx.iot.ap-northeast-1.amazonaws.com \
--root-ca ../../certs/root.ca.pem \
--cert ../../certs/bootstrap-certificate.pem.crt \
--key ../../certs/bootstrap-private.pem.key \
--templateName production_template \
--templateParameters '{"SerialNumber": 9999, "hasValidAccount": false}'
実行結果(ところどころ伏せたり端折ったりしてます)
Connecting to xxxxxxxxxx.iot.ap-northeast-1.amazonaws.com with client ID 'samples-client-id'...
Connected!
Subscribing to CreateKeysAndCertificate Accepted topic...
Subscribing to CreateKeysAndCertificate Rejected topic...
Subscribing to RegisterThing Accepted topic...
Subscribing to RegisterThing Rejected topic...
Publishing to CreateKeysAndCertificate...
Waiting... CreateKeysAndCertificateResponse: null
Published CreateKeysAndCertificate request..
Received a new message awsiot.iotidentity.CreateKeysAndCertificateResponse(certificate_id='xxxxxxxxxx', certificate_ownership_token='xxxxxxxxxx', certificate_pem='-----BEGIN CERTIFICATE-----\nxxxxxxxxxx\n-----END CERTIFICATE-----\n', private_key='-----BEGIN RSA PRIVATE KEY-----\nxxxxxxxxxx\n-----END RSA PRIVATE KEY-----\n')
Publishing to RegisterThing topic...
Waiting... RegisterThingResponse: null
Published RegisterThing request..
Received a new message awsiot.iotidentity.RegisterThingResponse(device_configuration={}, thing_name='born_9999')
Exiting Sample: success
Disconnecting...
Disconnected.
https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/provision-wo-cert.html https://aws.amazon.com/jp/about-aws/whats-new/2020/04/announcing-general-availability-of-aws-iot-core-fleet-provisioning/ https://aws.amazon.com/jp/blogs/news/how-to-automate-onboarding-of-iot-devices-to-aws-iot-core-at-scale-with-fleet-provisioning/ https://qiita.com/tatsuhiroiida/items/46ef5035f99b304d3d6f
過去にQiitaに投稿した内容のアーカイブです。
簡単なPythonプログラムをFargateで実行するまでの道のりです。
import os
import boto3
bucket = os.getenv('BUCKET_NAME', '')
key = 'HelloWorld.txt'
body = 'Hello, World!'
s3 = boto3.client('s3')
s3.put_object(Bucket=bucket, Key=key, Body=body)
環境変数で渡したバケットに固定文字列のファイルを出力するだけです。
試した環境は
7/7 更新 S3エンドポイントは不要でしたので記述を削除しました。
python -m venv .venv
.venv\Scripts\activate
pip install boto3 awscli
aws configure
AWS Access Key ID [None]: [アクセスキー]
AWS Secret Access Key [None]: [シークレットアクセスキー]
Default region name [None]: [ap-northeast-1などのリージョン]
Default output format [None]:
バケット名は環境変数から取得するようにしたので、環境変数にバケット名をセットします
set BUCKET_NAME=[バケット名]
python -m app
無事、S3にファイルが出力されました。
requirements.txtとDockerfileを用意し、app.pyと同じフォルダーに格納します。
boto3==1.9.183
FROM python:alpine
WORKDIR /app
ADD . /app
RUN python3 -m pip install -r requirements.txt
CMD ["python3", "-m", "app"]
docker build -t [Dockerイメージのタグ名] .
コンテナ内にはAWSの認証情報がないので、環境変数で渡します。バケット名も同様です。
docker run -e AWS_ACCESS_KEY_ID=[アクセスキー] -e AWS_SECRET_ACCESS_KEY=[シークレットアクセスキー] -e BUCKET_NAME=[バケット名] [Dockerイメージのタグ名]
無事、S3にファイルが出力されました。
Fargateで実行するため、DockerイメージをECR(Elastic Container Registry)に登録します。
aws ecr create-repository --repository-name [リポジトリ名]
aws ecr get-login --no-include-email
コンソールに出力されるコマンドを実行します。
docker image tag [ローカルのDockerイメージのタグ名] [リポジトリ名]:[リモートのDockerイメージ名]
docker image push [リポジトリ名]:[リモートのDockerイメージ名]
マネジメントコンソールでECSの画面を表示。クラスターを作成する。
| 設定項目 | 設定内容 |
|---|---|
| クラスターテンプレートの選択 | ネットワーキングのみ |
| クラスターの設定 | このクラスター用の新しいVPCを作る |
マネジメントコンソールでECSの画面を表示。タスク定義を作成する。
| 設定項目 | 設定内容 |
|---|---|
| 起動タイプの互換性の選択 | FARGATE |
| タスクとコンテナの定義の設定 | ↓↓↓ |
| タスク実行ロール | AmazonECSTaskExecutionRolePolicyの他にS3へのPutObject権限も必要 |
| コンテナの定義 | ↓↓↓ |
| イメージ | ECRのイメージ URI(マネジメントコンソールで確認する) |
| 環境変数 | BUCKET_NAMEにバケット名を指定 |
タスク定義から作成したものを選び、アクションのタスクの実行を行います。
| 設定項目 | 設定内容 |
|---|---|
| 起動タイプ | FARGATE |
| クラスター | 作成したもの |
| タスクの数 | 1 |
| VPC | 作成したもの |
ウィザードの最後のタスクの実行を押すと、実行されます。
クラスターから作成したものを選び、画面下のタブにあるタスクのスケジューリングの先の作成を選びます。
| 設定項目 | 設定内容 |
|---|---|
| スケジュールルールタイプ | お好みで |
| 起動タイプ | FARGATE |
| タスク定義 | 作成したもの |
| タスクの数 | 1 |
| クラスター VPC | 作成したもの |
ウィザードの最後の作成を押すと、指定したスケジュールに従って実行されます。
固定された間隔で実行の場合、初回起動は作成を押してから固定された間隔が経過したあとになるようです。
後半がかなり手抜きになりましたが、一応Fargateで動作するところまでできました。
過去にQiitaに投稿した内容のアーカイブです。
AWSサービス一覧がかなりのいいねをいただきましたので第2段です。
AWSのサービスの東京リージョン、大阪ローカルリージョンの対応状況をまとめました。
最新情報はこちらです https://aws.amazon.com/jp/about-aws/global-infrastructure/regional-product-services/
| サービス名 |
|---|
| Amazon CloudWatch |
| Amazon CloudWatch Events |
| Amazon CloudWatch Logs |
| Amazon DynamoDB |
| Amazon EC2 Auto Scaling |
| Amazon ElastiCache |
| Amazon Elastic Block Store (EBS) |
| Amazon Elastic Compute Cloud (EC2) |
| Amazon Elastic MapReduce |
| Amazon Glacier |
| Amazon Kinesis Data Streams |
| Amazon Redshift |
| Amazon Relational Database Service (RDS) |
| Amazon Simple Notification Service (SNS) |
| Amazon Simple Queue Service (SQS) |
| Amazon Simple Storage Service (S3) |
| Amazon Simple Workflow Service (SWF) |
| Amazon Virtual Private Cloud (VPC) |
| AWS Certificate Manager |
| AWS CloudFormation |
| AWS CloudTrail |
| AWS CodeDeploy |
| AWS Direct Connect |
| AWS Elastic Beanstalk |
| AWS Key Management Service |
| AWS Personal Health Dashboard |
| AWS サポート |
| Elastic Load Balancing |
| サービス名 |
|---|
| Amazon API Gateway |
| Amazon AppStream 2.0 |
| Amazon Athena |
| Amazon Aurora – MySQL-互換性 |
| Amazon Aurora – PostgreSQL-互換性 |
| Amazon CloudSearch |
| Amazon Cognito |
| Amazon Connect |
| Amazon Elastic Container Registry (ECR) |
| Amazon Elastic Container Service (ECS) |
| Amazon Elastic Container Service for Kubernetes (EKS) |
| Amazon Elastic File System (EFS) |
| Amazon Elastic Graphics |
| Amazon Elastic Inference |
| Amazon Elasticsearch Service |
| Amazon Elastic Transcoder |
| Amazon FreeRTOS |
| Amazon GameLift |
| Amazon GuardDuty |
| Amazon Inspector |
| Amazon Kinesis Data Firehose |
| Amazon Kinesis Video Streams |
| Amazon Lightsail |
| Amazon MQ |
| Amazon Polly |
| Amazon QuickSight |
| Amazon Rekognition Image |
| Amazon Rekognition Video |
| Amazon SageMaker |
| Amazon SageMaker Ground Truth |
| Amazon SimpleDB |
| Amazon Sumerian |
| Amazon WorkDocs |
| Amazon WorkSpaces |
| AWS AppSync |
| AWS Auto Scaling |
| AWS Batch |
| AWS Cloud Map |
| AWS CloudHSM |
| AWS CloudHSM Classic |
| AWS CodeBuild |
| AWS CodeCommit |
| AWS CodePipeline |
| AWS CodeStar |
| AWS Config |
| AWS Database Migration Service |
| AWS Data Pipeline |
| AWS DataSync |
| AWS Directory Service |
| AWS Elemental MediaConnect |
| AWS Elemental MediaConvert |
| AWS Elemental MediaLive |
| AWS Elemental MediaPackage |
| AWS Elemental MediaStore |
| AWS Elemental MediaTailor |
| AWS Fargate |
| AWS Firewall Manager |
| AWS Global Accelerator |
| AWS Glue |
| AWS Greengrass |
| AWS IoT 1-Click |
| AWS IoT Analytics |
| AWS IoT Core |
| AWS IoT Device Defender |
| AWS IoT Device Management |
| AWS Lambda |
| AWS Managed Services |
| AWS Marketplace |
| AWS Mobile Hub |
| AWS OpsWorks スタック |
| AWS OpsWorks for Chef Automate |
| AWS OpsWorks for Puppet Enterprise |
| AWS Secrets Manager |
| AWS Security Hub |
| AWS Serverless Application Repository |
| AWS Server Migration Service |
| AWS Service Catalog |
| AWS Shield Standard |
| AWS Shield Advanced |
| AWS Snowball |
| AWS Snowball Edge |
| AWS Snowmobile |
| AWS Step Functions |
| AWS Storage Gateway |
| AWS Systems Manager |
| AWS Trusted Advisor |
| AWS WAF |
| AWS X-Ray |
| VM Import/Export |
| サービス名 |
|---|
| Alexa for Business |
| Amazon Chime |
| Amazon Cloud Directory |
| Amazon Comprehend |
| Amazon Kinesis Data Analytics |
| Amazon Lex |
| Amazon Machine Learning |
| Amazon Macie |
| Amazon Mobile Analytics |
| Amazon Neptune |
| Amazon Pinpoint |
| Amazon Simple Email Service (SES) |
| Amazon Transcribe |
| Amazon Translate |
| Amazon WorkMail |
| Amazon WorkSpaces Application Manager |
| AWS Application Discovery Service |
| AWS Cloud9 |
| AWS Device Farm |
| AWS Migration Hub |
| AWS Transit Gateway |
大阪ローカルリージョンで提供されているサービスがかなり限定的なことと、東京リージョンにはほとんどのサービスが提供されていることがわかります。
import requests
from bs4 import BeautifulSoup
def parse_html_region():
url = 'https://aws.amazon.com/jp/about-aws/global-infrastructure/regional-product-services/'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
table = soup.find('div', id="element-0eb92496-750c-475f-9def-ee305caff349")
row = {}
for tr in table.find_all('tr'):
column = []
for td in tr.find_all('td'):
column.append(td.text.replace(u"\xa0",u""))
row[column[0]] = column
return row
regions = parse_html_region()
print ('### 東京リージョンにも大阪ローカルリージョンにもあるサービス')
print ()
print('| サービス名 |')
print('| --- |')
for key in regions:
service = regions[key]
tokyo = service[2]
osaka = service[3]
if (tokyo == '✓') and (osaka == '✓'):
print('| %s |' % (service[0]))
print ()
print ('### 東京リージョンにはあるけど大阪リージョンにないサービス')
print ()
print('| サービス名 |')
print('| --- |')
for key in regions:
service = regions[key]
tokyo = service[2]
osaka = service[3]
if (tokyo == '✓') and (not osaka):
print('| %s |' % (service[0]))
print ()
print ('### 東京リージョンにも大阪ローカルリージョンにもないサービス')
print ()
print('| サービス名 |')
print('| --- |')
for key in regions:
service = regions[key]
tokyo = service[2]
osaka = service[3]
if (not tokyo):
print('| %s |' % (service[0]))