{"id":19208614,"url":"https://github.com/heiwa4126/sam-s3event1","last_synced_at":"2026-06-19T15:03:13.756Z","repository":{"id":111911408,"uuid":"553380109","full_name":"heiwa4126/sam-s3event1","owner":"heiwa4126","description":"1つのスタックを2回にわけてデプロイしないといけないSAMのサンプル","archived":false,"fork":false,"pushed_at":"2022-10-18T07:10:34.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-04T16:18:44.325Z","etag":null,"topics":["aws-sam","example"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heiwa4126.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T06:00:58.000Z","updated_at":"2022-10-18T06:01:41.000Z","dependencies_parsed_at":"2023-04-18T14:30:45.118Z","dependency_job_id":null,"html_url":"https://github.com/heiwa4126/sam-s3event1","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fsam-s3event1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fsam-s3event1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fsam-s3event1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiwa4126%2Fsam-s3event1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heiwa4126","download_url":"https://codeload.github.com/heiwa4126/sam-s3event1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240280984,"owners_count":19776418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-sam","example"],"created_at":"2024-11-09T13:27:11.879Z","updated_at":"2026-06-19T15:03:08.737Z","avatar_url":"https://github.com/heiwa4126.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sam-s3event1\n\nS3イベントをトリガにしてlambdaを起動する。\nだがそのlambdaはイベント元のS3に依存している、という場合、\n1つのスタックを2回にわけてデプロイしないといけない、\nというSAMのサンプル。\n\n参考:\n[AWS::S3::Bucket NotificationConfiguration - AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig.html) の冒頭のnote参照。\n\n上記該当部分の機械翻訳(DeepL)\n\u003e 対象リソースと関連するパーミッションを同じテンプレートで作成した場合、循環的な依存関係が発生する可能性があります。\n\u003e\n\u003e 例えば、AWS::Lambda::Permissionリソースを使用して、バケットにAWS Lambda関数を呼び出す権限を付与することができます。しかし、AWS CloudFormationはバケットに関数を呼び出す権限がないとバケットを作成できません（AWS CloudFormationはバケットが関数を呼び出すことができるかどうかをチェックします）。Refsを使ってバケット名を渡している場合、これは循環依存につながります。\n\u003e\n\u003e この依存関係を回避するには、通知設定を指定せずにすべてのリソースを作成します。その後、通知設定を使ってスタックを更新します。\n\n\n# デプロイ\n\n```bash\n./1to0.sh  # template.yamlからtmp0.yaml(最初のデプロイ用テンプレート)を生成する\nsam build\nsam deploy -t tmp0.yaml -g  # 全部デフォルトで(returnキーを押すだけ)。2回目からは-g(--guided)ぬきで\nsam deploy\n```\n\n\n# テスト\n\nデプロイ終了後\n\n```bash\n./make_env.sh  # デプロイ毎に1回実行\n./tail_samlog.sh  # tmuxなどで別ペインで実行するのがおすすめ\n```\n\nで、\n```bash\n./put_s3.sh\n```\nすると、しばらく(10秒ぐらい?)たってから最新ログが表示される。\n\n\n```bash\n./rm_s3.sh \u0026\u0026 ./put_s3.sh\n```\nで何度でもテストできる。\n\n\n# スタックの削除\n\n```bash\n./stop_samlog.sh\n./rm_s3.sh\nsam delete --no-prompts\n```\n\n\n# ポイント\n\ntemplate.yaml も\ntmp0.yaml も\n循環依存(circular dependency)があってはいけない。\n事前に [cfn-lint](https://github.com/aws-cloudformation/cfn-lint)でチェックしておくべき。\n\nこのケースでは\n[AWS::Serverless::Function](https://docs.aws.amazon.com/ja_jp/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-events) の\n[S3イベント](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-s3.html)\nも使えない。\n\n\n# TODO\n\ntemplate.yaml から\ntemplate0.yaml を自動生成できるような工夫を考えること\n-\u003e done. `1to0.sh`がそれ。\n\nあとTerraformではどうなのか確認すること。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiwa4126%2Fsam-s3event1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheiwa4126%2Fsam-s3event1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiwa4126%2Fsam-s3event1/lists"}