概要
m1 mac で terraform を動かすと、
Error: rpc error: code = Unavailable desc = transport is closing
というエラーが出ることがある。
その際の対処法を紹介
解決方法
以下の環境変数を追加するだけ
export GODEBUG=asyncpreemptoff=1
~/.zshrc
などに追記するなど行う。
m1 mac で terraform を動かすと、
Error: rpc error: code = Unavailable desc = transport is closing
というエラーが出ることがある。
その際の対処法を紹介
以下の環境変数を追加するだけ
export GODEBUG=asyncpreemptoff=1
~/.zshrc
などに追記するなど行う。
プ譜についての説明が後半を締めているが、その部分は割愛し、あくまでもプロジェクトの進行についてだけまとめる。
正解のない状況では正しく問いを立て、人々を方向づける技術が求められる
集団作業における混乱をおさめる
全体は計画的に進め、細部は試行錯誤で進める
言葉の認識を合わせる。ユビキタス言語を作ることなどその一例。
また、言葉の認識を合わせる方法として、
上記2点がとても重要であり、必ずどこかに誤解があるはずだと考えてコミュニケーションを取るのが重要になる。
以下3点を抑える
本書では上記の通り記載があったが、自分は上記に加えて2点必要ではないかと考える
予め話すべき内容は共有されており、想定外の事態への想像を促す場と捉える
以下の3点をアジェンダに入れるよう書いてある
アジェンダが全員が集まらないと意思決定できないものだけになることが理想
各工程の開始条件、終了条件が明確になっていること
コンテナが広く使われるようになり、
EC2 instanceは徐々に使わなくなってきたが、それでもEC2 instance を使っているところはまだまだ多い。
EC2 instance に接続するには ElasticIP を使ってssh を使うのが一般的だが、
ElasticIP は便利なために、長年運用している間に気がつけばだんだん増えていってしまいがちである。
踏み台サーバのような ssh しか使わないサーバであれば、極力 ElasticIP を使わずいけるようにしたい。
接続先のAWS EC2 側の設定と、接続元のMac に設定をまとめた。
sudo yum install -y https://s3.ap-northeast-1.amazonaws.com/amazon-ssm-ap-northeast-1/latest/linux_amd64/amazon-ssm-agent.rpm
ap-northeast-1 の場合は上記の通りだが、
他のリーションを使うことになれば上記よしなに変更する
EC2 インスタンスに Attach している IAM role に
SSM のロールを Attach する。
AmazonSSMManagedInstanceCore
という AWS管理のポリシーがあるので、これを Attach
直に aws コマンドをインストールしてもよいが、ローカル環境が汚れるのが嫌なので(これは完全に趣向性)
自分はaws コマンドを叩くと、aws cli のコンテナが動くようにしている。
公式のaws cli のコンテナは何のプラグインも入ってないプレーンな状態なので、
session-manager-plugin をインストールした。
vi Dockerfile
FROM amazon/aws-cli
RUN curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" -o "session-manager-plugin.rpm" && \
yum install -y ./session-manager-plugin.rpm
docker image build -t ssm/aws-cli:latest .
.ssh/config
に以下の通り設定を入れる
host bastion
User ec2-user
ProxyCommand sh -c "docker run --rm -i -v ~/.aws:/root/.aws -v $(pwd):/aws --env AWS_PAGER="" ssm/aws-cli ssm --profile staging start-session --target i-08afxxxxxxxxxx --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
IdentityFile ~/.ssh/ec2-user
他のサーバに対して同様の設定をする際は
インスタンスID i-08afxxxxxxxxxx
や User, IdentityFileを変更すれば良い
また、今回は接続先が BT 環境のため --profile staging
としたが、他の環境に接続する際はここを適宜変更する。
今まで ElasticIP を使って接続していたことと同様に接続できることを確認できた。
% ssh bastion
Last login: Mon May 9 10:31:34 2022 from localhost
__| __|_ )
_| ( / Amazon Linux 2 AMI
___|\___|___|
https://aws.amazon.com/amazon-linux-2/
[ec2-user@bastion ~]$
コードフォーマッターとしての Prettier (プリティア)をプロジェクトに組み込む方法を紹介。
また、2021 年に静的検証ツールとしての ESLintがPrettierが merge され、今までは別々にインストールする必要があったが、 Prettier のみインストールすればよくなった。
“prettier/@typescript-eslint” has been merged into “prettier” in eslint-config-prettier 8.0.0. See: https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21
インストール方法は以下の通り
npm install -D prettier eslint-config-prettier eslint-plugin-prettier
npm init @eslint/config
Ok to proceed? (y) y
✔ How would you like to use ESLint? · problems
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · none
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ What format do you want your config file to be in? · JavaScript
The config that you've selected requires the following dependencies:
@typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest
✔ Would you like to install them now with npm? · No / Yes
Installing @typescript-eslint/eslint-plugin@latest, @typescript-eslint/parser@latest
removed 7 packages, and audited 858 packages in 4s
47 packages are looking for funding
run `npm fund` for details
1 critical severity vulnerability
To address all issues, run:
npm audit fix
Run `npm audit` for details.
A config file was generated, but the config file itself may not follow your linting rules.
Successfully created .eslintrc.js file in /Users/sumito.tsukada/go/src/git.rarejob.com/rarejob-platform/account-web/aws/rjpf-student-account-web-alb-ecsc-ecr-cdeploy
プロジェクト直下に js を配置
vi .prettierrc.js
module.exports = {
singleQuote: true,
tabWidth: 4,
trailingComma: 'es5',
};
package.json を一部修正
"build": "tsc",
"watch": "tsc -w",
"test": "jest",
- "cdk": "cdk"
+ "cdk": "cdk",
+ "lint": "eslint --ext .ts ."
},
"devDependencies": {
"@aws-cdk/assertions": "1.135.0",
警告
npm run lint
> sample@0.1.0 lint
> eslint --ext .ts .
sample.test.ts
1:20 warning 'Match' is defined but never used @typescript-eslint/no-unused-vars
✖ 1 problem (0 errors, 1 warning)
cdk init コマンドによりはじめることができる
cdk init sample-app --language=typescript
出力結果は以下の通り
% cdk init sample-app --language=typescript
Applying project template sample-app for typescript
# Welcome to your CDK TypeScript project!
You should explore the contents of this project. It demonstrates a CDK app with an instance of a stack (`RjpfStudentAccountWebAlbEcscEcrCdeployStack`)
which contains an Amazon SQS queue that is subscribed to an Amazon SNS topic.
The `cdk.json` file tells the CDK Toolkit how to execute your app.
## Tutorial
See [this useful workshop](https://cdkworkshop.com/20-typescript.html) on working with the AWS CDK for Typescript projects.
## Useful commands
* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template
Executing npm install...
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
✅ All done!
上記は sample-app としたことで、作成されたファイル群にサンプルコードを入れることができるが、
cdk init app --language=typescript
にすれば空の CDK アプリケーションを作成することができ、
cdk init lib --language=typescript
と指定すれば Constructライブラリを生成することができる。こちらのコマンドは TypeScript のみ対応しているようだ。
Python で jsonの変数を持たせたいことがあり、読み込む上でのメモ
import json
list = [{"name":"Worker","no":"123"}, {"name":"User","no":"456"}, {"name":"Organization","no":"789"}, {"name": "Position","no":"123"}, {"name": "PositionTranslation","no":"123"}]
for d in list:
print(d.get('name'))
print(d.get('no'))
print("-----")
list の中に json の配列を格納
loop の中で .get(key名)を行うことで value を取り出すことができる
結果
Worker
123
-----
User
456
-----
Organization
789
-----
Position
123
-----
PositionTranslation
123
-----
一時領域を作ることができないほどdiskが圧迫している。
空き容量を確保する
docker rm -f $(docker ps -a -q)
docker builder prune -a -f
上記両方を行うことで容量を確保できることが多い。
手元のテキストファイルを単純に zipファイル化するためのメモ
以下のディレクトリ構成とする
% tree a
a
└── 1.csv
a というディレクトリの配下に 1.csv というファイルが存在したとする
python3 でzip 化
import zipfile
with zipfile.ZipFile('1.csv.zip', "w", compression=zipfile.ZIP_DEFLATED) as zf:
zf.write('a/1.csv',arcname='1.csv')
a/1.csv を圧縮し、a/1.csv.zip というファイルを生成する。
a/1.csv.zip を解凍すると、1.csv という名前のファイルが直下に作成される。
python zip.py
直下に
1.csv.zip
が作られる。
解凍する
% unzip 1.csv.zip
Archive: 1.csv.zip
inflating: 1.csv
無事解凍できたことを確認
% cat 1.csv
NO,CODE
1,987
Most of the tasks in aws can be operated with aws commands. The only command I couldn’t find in the official documentation was “create folder,” which should be on the screen.
In fact, the concept of folders does not exist in S3. https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/dev/UsingMetadata.html
The data model of Amazon S3 is a flat structure. Buckets are created and objects are stored in those buckets. There is no hierarchy of sub-buckets or sub-folders. However, a logical hierarchy can be implied by using key name prefixes and delimiters, such as those used in the Amazon S3 console.
So, for one bucket, there are no folders in it, and it is an image of a large number of files.
I don’t have a directory, but I’ll just dump it in directly!
aws s3 cp sample.txt s3://test/sample-folder/
This will create a sample-folder in the test bucket. Copy the sample.txt file into it. Reference: Breaking the illusion of “folder” in Amazon S3 and revealing its reality https://dev.classmethod.jp/cloud/aws/amazon-s3-folders/
If multiple environments are registered in the .aws directory, it is possible to specify the profile to be loaded with -profile role-a-profile.
If you want to copy the whole directory, use
--recursive
option to copy the entire directory recursively.
I ran out of storage on my docker build server. I need to delete unnecessary files, but there is a command to safely allocate space.
Identify what is putting pressure on the disk in docker.
Use docker system df
command, you can identify the disk usage related to docker.
# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 9 1 2.014GB 1.962GB (97%) Containers 2 0 0B 0B Local Volumes 4 2 824.6MB 781.2MB (94%) Build Cache 0 0 0B 0B
It will remove stopped containers, unused volumes, unused networks, and unused images.
docker system prune
However, the option to delete unused volumes and images is required.
# docker system prune --help Usage: docker system prune [OPTIONS] Remove unused data Options: -a, --all Remove all unused images not just dangling ones --filter filter Provide filter values (e.g. 'label=<key>=<value>') -f, --force Do not prompt for confirmation --volumes Prune volumes
I was able to reduce the size of the file by 355.4MB.
553d15cd6b78ad0f21788a22e9ce16a7295c4bab97609973 deleted: sha256:7ae9338aed73a0f33568db53740431038d3a1f779c4dae40d27433984e1cd97c deleted: sha256:b1be54c8cadff1e50b87b93559320a1ae57b8d0dd326507148f7ca81d707beed deleted: sha256:86d78f10b9718618eaae056f5dfa1edae518949aee4578e4147268e9db2e75f0 Total reclaimed space: 355.4MB
However, this does not remove the storage.
use –volumes
optiion. you can also delete storage.
docker system prune --volumes WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all volumes not used by at least one container - all dangling images - all build cache Are you sure you want to continue? [y/N] y
If you choose –all
option. you can also delete images.
# docker system prune --all WARNING! This will remove: - all stopped containers - all networks not used by at least one container - all images without at least one container associated to them - all build cache Are you sure you want to continue? [y/N]
When you finish deleting unnecessary files, it will be zero.
# docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 0 0 0B 0B Containers 0 0 0B 0B Local Volumes 0 0 0B 0B Build Cache 0 0 0B 0B