The bucket does not allow ACLs エラーに出くわしたので調べる

Bucket作成時のACLエラー Terraform で環境構築時に下記エラーが発生 ACL周りのデフォルト動作が変更となったようなので、少しメモ Error: error creating S3 bucket ACL for sample-bucket: AccessControlListNotSupported: The bucket does not allow ACLs status code: 400, request id: xxxxxxxxxxxxxxxx, host id: xxxxxxxxxxxxxxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxxx/xxxxxxx/xxxxxxxxxxxxxxxxxxxxxx with module.s3.aws_s3_bucket_acl.sample, on ../../module_aws/s3/main.tf line 13, in resource "aws_s3_bucket_acl" "sample": 13: resource "aws_s3_bucket_acl" "sample" { S3作成時のデフォルトの設定の変更 2023年4月より新規S3バケットは、デフォルトでパブリック・アクセスブロック有効化、ACL無効化 ACLは利用しないことが推奨される s3オブジェクトのACL有効・無効設定は aws_s3_bucket_ownership_controls で設定する resource "aws_s3_bucket_ownership_controls" "sample" { bucket = aws_s3_bucket.sample.bucket rule { object_ownership = "BucketOwnerEnforced" } } object_ownership に設定できるのは以下 ObjectWriter: 所有者はアップローダ BucketOwnerPreferred: バケット所有アカウントを指定可能(bucket-owner-full-control) BucketOwnerEnforced: バケット所有アカウント強制 BucketOwnerEnforced ではACL併用できない S3 ポリシー適用時のエラー S3 policy: AccessDenied: Access Denied 一部ディレクトリのみ公開したい場合など、ACLを指定する場合は、ObjectWriter & ACL設定 & ポリシーにはアカウントを指定する...

2023-05-08 ·  2023-09-22 · 1 分 · 107 文字

Golangでディレクトリ内が空かどうかを判定する

最終的にはこれ func IsEmpty(name string) (bool, error) { f, err := os.Open(name) if err != nil { return false, err } defer f.Close() _, err = f.Readdirnames(1) // Or f.Readdir(1) if err == io.EOF { return true, nil } return false, err // Either not empty or error, suits both cases } つまり システムにはディレクトリが空かどうかの情報は無いからディレクトリの子があるかどうかで判断するしか無い File.Readdirnames() が最速 以下日本語要約 ディレクトリが空であるか否かは、その名前、作成時間、またはそのサイズ(ファイルの場合)のようなファイルシステムレベルのプロパティとして保存されていません。 つまり、os.FileInfoからこの情報を直接取得することはできません。最も簡単な方法は、ディレクトリの子(内容)をクエリすることです。 ioutil.ReadDir()はあまり良い選択ではありません。なぜなら、これはまず指定されたディレクトリのすべての内容を読み取り、それらを名前でソートし、その後スライスを返すからです。最も速い方法はDave Cが言及したように、File.Readdir()または(好ましくは)File.Readdirnames()を使用してディレクトリの子をクエリすることです。 File.Readdir()とFile.Readdirnames()の両方は、返される値の数を制限するために使用されるパラメータを取ります。1つの子をクエリするだけで十分です。Readdirnames()は名前のみを返すので、FileInfo構造体を取得(および構築)するためのさらなる呼び出しが必要ないため、速度が速くなります。 ディレクトリが空の場合、io.EOFがエラーとして返され(空のスライスやnilのスライスではない)ため、返された名前のスライスは必要ありません。 以下抜粋 Whether a directory is empty or not is not stored in the file-system level as properties like its name, creation time or its size (in case of files)....

2023-04-21 ·  2023-05-14 · 2 分 · 259 文字

node.js firebase-admin の multicast 時のレスポンスの配列と、指定したトークンの配列順序は一致する

Firebase Cloud Messagingで firebase-admin - npm 使って Multicastすると、複数のデバイスに対して一度にプッシュ通知を送信することができるけど、 どのTokenが失敗したのかわからないのでは?と思い調べた So to confirm, the response array from sendMulticast is in the same order as the tokens that were passed in, allowing you to match up the indexes of any errors. https://stackoverflow.com/questions/70008515/firebase-cloud-messaging-multicast-error-messaging-registration-token-not-regist ここにある通り、 multicast 時のトークン配列と、 応答される BatchResponse の配列順序は一致する らしいので、どのトークンが失敗したのかはわかるみたい

2023-03-01 ·  2023-04-21 · 1 分 · 47 文字

Chrome拡張で現在のタブ情報を取る方法(v3)

公式に記載のある通りだけど、 少し調べたので、メモをおいておく v3用 Promise const getCurrentTab = async () => { const queryOptions = { active: true, lastFocusedWindow: true }; // `tab` will either be a `tabs.Tab` instance or `undefined`. const [tab] = await chrome.tabs.query(queryOptions); return tab; }; Refs chrome.tabs - Chrome Developers

2023-02-25 ·  2023-02-25 · 1 分 · 43 文字

Serverless で ApiGw のロギングいれようとして、`CloudWatch Logs role ARN must be set in account settings to enable logging` となったのでメモ

問題 Serverless Framework で、以下のようにロギング設定を追加して、以下エラーになった provider: # 省略 logs: restApi: accessLogging: false # Optional configuration which enables or disables access logging. Defaults to true. executionLogging: true # Optional configuration which enables or disables execution logging. Defaults to true. level: ERROR # Optional configuration which specifies the log level to use for execution logging. May be set to either INFO or ERROR. fullExecutionData: false # Optional configuration which specifies whether or not to log full requests/responses for execution logging....

2023-02-13 ·  2023-04-24 · 1 分 · 130 文字