EC2 mount EFS

AWS EC2 moutn EFS E2 からマウント 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/bin/bash EFS_ID="fs-0f90bd97a364a6e94" # PKG=amazon-efs-utils RES=$(dpkg --get-selections | grep $PKG) MOUNT_PATH="/efs" if [ -z "${RES}" ]; then apt update && apt upgrade -y && apt autoremove -y apt-get -y install binutils git clone https://github.com/aws/efs-utils cd efs-utils ./build-deb.sh apt-get install -y ./build/amazon-efs-utils*deb fi # if [ ! -d $MOUNT_PATH ]; then mkdir $MOUNT_PATH fi # mount -t efs $EFS_ID:/ $MOUNT_PATH

2023年7月12日 · 1 分

Cloud Function defautl pages

AWS CloudFuntion URL 変更 AWS CloudFront Functions を使用して、ブラウザリクエストの URL を書き換えてオリジンに送信するには、HTTP リクエストを別の URL にリダイレクトする関数を作成する必要があります。 AWS ドキュメントには、CloudFront Functions を使用して HTTP リクエストを別の URL にリダイレクトする方法が記載されています ¹。 また、Classmethod 社の記事には、CloudFront Functions でオリジンに手を加えずに URL リダイレクトを行う方法が記載されています ³。 ご参考までに、以下は CloudFront Functions で HTTP リクエストを別の URL にリダイレクトする例です ²。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function handler(event) { var request = event.request; var headers = request.headers; var uri = request.uri; var host = headers.host.value; var newurl = null; // Check the URI is '/abc/sign-up'. if (uri === "/abc/sign-up") { newurl = `https://${host}/sign-up`; } if (newurl !== null) { return { statusCode: 301, statusDescription: "Moved Permanently", headers: { location: { value: newurl }, }, }; } return request; } この例では、URI が/abc/sign-upに一致した場合に、https://${host}/sign-upへリダイレクトしています。この例を参考に、ご自身の環境に合わせた関数を作成してください。 ...

2023年6月26日 · 2 分

AWS SES Logging

AWS SES ロギング Amazon SES ログにはどのようにアクセスできますか? Amazon SES でのメール送信ログを表示する AWS CloudTrail を使用した Amazon SES API コールのログ作成 SESの送信履歴を確認したい Terrafrom + Firefose Firehoseを使用してSESのログをS3バケットに記録するには、Terraformで以下のように記述することができます。 resource "aws_s3_bucket" "log_bucket" { bucket = "log-bucket" } resource "aws_ses_domain_identity" "example" { domain = "example.com" } resource "aws_ses_domain_identity_verification" "example" { domain = aws_ses_domain_identity.example.domain } resource "aws_ses_configuration_set" "example" { name = "example" } resource "aws_ses_event_destination" "example" { configuration_set_name = aws_ses_configuration_set.example.name name = "example" enabled = true kinesis_firehose_destination { role_arn = aws_iam_role.firehose_role.arn delivery_stream_arn = aws_kinesis_firehose_delivery_stream.firehose.arn } matching_types = [ "send", "reject", "bounce", "complaint", "delivery", "open", "click", ] } このコードでは、S3バケットを作成し、SESドメイン識別子を作成し、検証し、構成セットを作成し、イベント宛先を作成しています。 ...

2023年5月17日 · 1 分

redis

redis Ubuntu 1 sudo apt update && sudo apt install redis-server -y 1 2 $ ps ax | grep redis 1083463 ? Ssl 0:00 /usr/bin/redis-server 127.0.0.1:6379 redis-cli redis-cliコマンドでデータベース1に接続するには、次のように入力します。¹² redis-cli -n 1 このコマンドは、データベース1に接続するためのものです。-nオプションを使用して、データベース番号を指定します。 上記の例では、データベース番号が1であることを示しています。 ソース: Bing との会話 2023/5/5 (1) redis-cliの接続時によく使うコマンド使い方メモ - Qiita. https://qiita.com/a-nishimura/items/54b0d85dbce47685a36f. (2) 【入門】Redis - Qiita. https://qiita.com/wind-up-bird/items/f2d41d08e86789322c71. (3) redis-cliの使い方 - Qiita. https://qiita.com/sawada_masahiko/items/1f60936c421ecab8dfbf. (4) redis-cliでよく使うコマンド20選 - Qiita. https://qiita.com/hatsu/items/a52817364160e0b6bb60. (5) Redisコマンド一覧 - Qiita. https://qiita.com/taiba/items/18016906d80c13e88853. (6) リモート環境にあるRedisに接続する - 箱のプログラミング日記。. https://www.y-hakopro.com/entry/2020/10/31/185235. Django 1 poetry add django-redis settings.py: ...

2023年5月5日 · 1 分

Celery: supervisord

Celery: supervisord conf 1 2 3 4 5 6 7 8 9 10 11 12 [program:epm-tasks] directory=/home/ubuntu/projects/epm/web user=ubuntu command=/home/ubuntu/.anyenv/envs/pyenv/versions/coresys/bin/celery -A app worker -l INFO -f /home/ubuntu/projects/epm/logs/tasks.log autostart=true autorestart=true ;stdout_logfile=syslog ;stderr_logfile=syslog numprocs=1 startsecs=10 stopwaitsecs = 600 killasgroup=true -f オプションで指定すると user の所有権でファイル作成 stdout_logfile / stderr_logfile で指定するとsupervisord ユーザー(root)の所有権で作成 log rotation It seems that you are using supervisord to manage Celery processes and you want to rotate the log files for Celery on a daily basis. One way to do this is to use logrotate, a tool that can rotate and compress log files according to a configuration file². To use logrotate, you need to do the following steps: ...

2023年4月12日 · 2 分

Terraform

README tfenvのインストール 設定ファイルの作成 terraform init terraform plan terraform apply 設計運用 Terraform設計・運用のノウハウ ベストプラクティス antonbabenko/terraform-best-practices ファイル 内容 main.tf リソースを作成する(moduels, locals, data-sources) variables.tf main.tf で使われる変数 outputs.tf main.tf が作成したリソースの出力 1 % tree large-terraform large-terraform ├── README.md ├── modules │ └── network │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── prod │ ├── main.tf │ ├── outputs.tf │ ├── terraform.tfvars │ └── variables.tf └── stage ├── main.tf ├── outputs.tf ├── terraform.tfvars └── variables.tf HCL (HCL is the HashiCorp configuration language.) https://github.com/hashicorp/hcl Terraform v0.12で変わるHCLの記述について コメント: ...

2021年6月12日 · 1 分

AWS: ECS

ECS オートスケーリング 記事 Fargate で Amazon ECS サービスの自動スケーリングを設定する方法を教えてください。 AWS FargateでAutoScaleを試してみる Terraform の設定 オートスケーリングの設定をTerraformで記述する例を以下に示します。この例では、CPU使用率に基づいてECS Fargateサービスのタスク数を自動的にスケーリングするように設定します。 必要なリソース TerraformでECSサービスのオートスケーリングを設定するには、以下のリソースを定義します。 aws_appautoscaling_target: スケーリングの対象となるECSサービスとタスク数を指定します。 aws_appautoscaling_policy: 実際のスケーリングロジック(CPU使用率、目標値など)を定義します。 aws_cloudwatch_metric_alarm: (オプション) 詳細な条件でスケーリングを制御する場合に使用します。ターゲット追跡スケーリングポリシーは内部でこれを生成するため、通常は明示的に定義する必要はありません。 Terraform コード例 以下のコードブロックは、aws_ecs_serviceリソースで定義されたECSサービスに対して、CPU使用率が50%になるようにタスク数を調整するオートスケーリング設定の例です。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 # ECSサービスを定義 (この例では、既存サービスを想定) # resource "aws_ecs_service" "main" { # name = "my-ecs-service" # ... # } # 1. オートスケーリングの対象を定義 resource "aws_appautoscaling_target" "ecs_target" { service_namespace = "ecs" resource_id = "service/my-cluster/my-ecs-service" # サービス名に合わせて変更 scalable_dimension = "ecs:service:DesiredCount" min_capacity = 1 # 最小タスク数 max_capacity = 10 # 最大タスク数 } # 2. ターゲット追跡スケーリングポリシーを定義 resource "aws_appautoscaling_policy" "cpu_scaling_policy" { name = "cpu-utilization-scaling-policy" service_namespace = "ecs" resource_id = aws_appautoscaling_target.ecs_target.resource_id scalable_dimension = aws_appautoscaling_target.ecs_target.scalable_dimension policy_type = "TargetTrackingScaling" target_tracking_scaling_policy_configuration { predefined_metric_specification { predefined_metric_type = "ECSServiceAverageCPUUtilization" } target_value = 50.0 # CPU使用率の目標値(%) scale_in_cooldown = 300 # スケールイン(タスク減少)のクールダウン期間(秒) scale_out_cooldown = 60 # スケールアウト(タスク増加)のクールダウン期間(秒) } } コードの解説 aws_appautoscaling_target: ...

2021年6月4日 · 1 分

Laravel: マイグレーション

Laravel マイグレーション Laravel マイグレーションを1つずつ戻す 1 $ php artisan migrate:rollback --step=1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 MySQL [mysite]> select * from migrations; +----+--------------------------------------------------------------+-------+ | id | migration | batch | +----+--------------------------------------------------------------+-------+ | 1 | 2014_10_12_000000_create_users_table | 1 | | 2 | 2014_10_12_100000_create_password_resets_table | 1 | | 3 | 2019_08_19_000000_create_failed_jobs_table | 1 | | 4 | 2019_12_14_000001_create_personal_access_tokens_table | 1 | | 5 | 2021_01_27_074301_create_sessions_table | 1 | | 6 | 2021_02_03_055949_create_products_table | 1 | | 7 | 2021_02_03_060047_create_news_table | 1 | | 8 | 2021_02_08_024947_create_credit_cards_table | 1 | | 9 | 2021_02_08_025236_create_licenses_table | 1 | | 10 | 2021_02_08_060434_create_orders_table | 1 | | 11 | 2021_02_18_124506_create_options_table | 1 | | 12 | 2021_03_10_093455_update_string_fields_to_text | 2 | | 13 | 2021_04_09_123358_add_users_deleted_at_field | 3 | | 14 | 2021_04_09_123459_add_licenses_subscription_cancelled_fields | 3 | +----+--------------------------------------------------------------+-------+ 14 rows in set (0.002 sec) 1 % php artisan migrate:rollback --step=1 ************************************** * Application In Production! * ************************************** Do you really wish to run this command? (yes/no) [no]: > yes Rolling back: 2021_04_09_123459_add_licenses_subscription_cancelled_fields Rolled back: 2021_04_09_123459_add_licenses_subscription_cancelled_fields (165.69ms) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 MySQL [mysite]> select * from migrations; +----+-------------------------------------------------------+-------+ | id | migration | batch | +----+-------------------------------------------------------+-------+ | 1 | 2014_10_12_000000_create_users_table | 1 | | 2 | 2014_10_12_100000_create_password_resets_table | 1 | | 3 | 2019_08_19_000000_create_failed_jobs_table | 1 | | 4 | 2019_12_14_000001_create_personal_access_tokens_table | 1 | | 5 | 2021_01_27_074301_create_sessions_table | 1 | | 6 | 2021_02_03_055949_create_products_table | 1 | | 7 | 2021_02_03_060047_create_news_table | 1 | | 8 | 2021_02_08_024947_create_credit_cards_table | 1 | | 9 | 2021_02_08_025236_create_licenses_table | 1 | | 10 | 2021_02_08_060434_create_orders_table | 1 | | 11 | 2021_02_18_124506_create_options_table | 1 | | 12 | 2021_03_10_093455_update_string_fields_to_text | 2 | | 13 | 2021_04_09_123358_add_users_deleted_at_field | 3 | +----+-------------------------------------------------------+-------+ 13 rows in set (0.002 sec)

2021年5月17日 · 2 分

Python:Exception

Python: Exception Python Exceptions: An Introduction 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 try: # 処理 linux_interaction() except AssertionError as error: # 例外 print(error) else: ## 例外がない場合 try: with open('file.log') as file: read_data = file.read() except FileNotFoundError as fnf_error: print(fnf_error) finally: # 最後に必ず実行 print('Cleaning up, irrespective of any exceptions.') Python Exception Base Classes 組み込み例外 8.6. ユーザー定義例外

2021年5月14日 · 1 分

Django Simple Docker File

% tree . -I '__*|db*' . ├── Dockerfile ├── poetry.lock ├── pyproject.toml └── web ├── blogsite │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py └── pages ├── admin.py ├── apps.py ├── migrations ├── models.py ├── tests.py ├── urls.py └── views.py 4 directories, 14 files

2021年2月19日 · 1 分