Closed16

既存のCopilot CLI環境にStatic Siteを追加したい

Takaaki KakeiTakaaki Kakei

svc init

% copilot svc init                                                                                                         2024/01/04 14:43:01 
Note: It's best to run this command in the root of your workspace.
Service type: Static Site
Service name: svc-dev-staticsite

envには、紐付けたいRequest-Driven Web Serviceのenvのmanifest.ymlを指定してみる

iac/copilot/svc-dev-staticsite/manifest.ymlのみ作成される

Takaaki KakeiTakaaki Kakei

manifest.yml修正

iac/copilot/svc-dev-staticsite/manifest.ymlを更新

# The manifest for the "svc-dev-staticsite" service.
# Read the full specification for the "Static Site" type at:
# https://aws.github.io/copilot-cli/docs/manifest/static-site/

# Your service name will be used in naming your resources like S3 buckets, etc.
name: svc-dev-staticsite
type: Static Site
files: # refs: https://aws.github.io/copilot-cli/ja/docs/manifest/static-site/
  - source: ../staticsite
    recursive: true
    destination: "assets"
    exclude: # 含まれない認識だが、念のため機微なファイル名は除外する
      - "*/.env"
      - "*/.env.local"
      - "*/.env.local.example"
      - "*.md"
# You can override any of the values defined above by environment.
# environments:
#   test:
#     files:
#       - source: './blob'
#         recursive: true
#         destination: 'assets'
#         exclude: '*'
#         reinclude:
#           - '*.txt'
#           - '*.png'

パラメータ情報は以下参照
https://aws.github.io/copilot-cli/ja/docs/manifest/static-site/

Takaaki KakeiTakaaki Kakei

copilot svc deploy

% copilot svc deploy                                                                                                       2024/01/04 15:05:35 
Name: svc-dev-staticsite
Only found one option, defaulting to: dev-rdws
✔ Proposing infrastructure changes for stack ai-starter-dev-rdws-svc-dev-staticsite
- Creating the infrastructure for stack ai-starter-dev-rdws-svc-dev-staticsite              [create complete]  [313.2s]
  - A bucket policy to grant CloudFront read access to the Static Site bucket               [create complete]  [0.0s]
  - An S3 Bucket to store the static site's assets                                          [create complete]  [29.9s]
  - A CloudFront distribution for global content delivery                                   [create complete]  [227.8s]
  - Access control to make the content in the S3 bucket only accessible through CloudFront  [create complete]  [3.8s]
  - CloudFront Function to rewrite viewer request to index.html                             [create complete]  [0.0s]
  - An IAM Role for the state machine that moves source files to the S3 bucket              [create complete]  [19.5s]
  - A state machine that moves source files to the S3 bucket                                [create complete]  [3.5s]
  - A policy that gives the Env Manager role access to this site's S3 Bucket                [create complete]  [15.6s]
  - A custom resource that starts the process of moving files to the S3 bucket              [create complete]  [3.2s]
  - An IAM Role for the lambda that starts the process of moving files to the S3 bucket     [create complete]  [18.3s]
  - A lambda that starts the process of moving files to the S3 bucket                       [create complete]  [10.2s]
✔ Deployed service svc-dev-staticsite.
Recommended follow-up action:
  - Your service is accessible at https://xxxxxx.cloudfront.net/ over the internet.
Takaaki KakeiTakaaki Kakei

手動で追加したリソースはデプロイで上書きされるか

Takaaki KakeiTakaaki Kakei

コード内でindex2.htmlを追加してデプロイしたが、既存のpngは削除されなかった

Takaaki KakeiTakaaki Kakei

以下の状態で再デプロイ

  • コード内でindex2.htmlを削除
  • バージョニングの設定を手動で無効化

結果

  • S3バケットからindex2.htmlは削除されなかった
  • バージョニングの設定変更は維持された
Takaaki KakeiTakaaki Kakei

Static Siteの情報をRequest-Driven Web Serviceから参照できるか

Takaaki KakeiTakaaki Kakei

ローカルで、環境変数でURLをセットして参照できるようにできることを確認済

このスクラップは4ヶ月前にクローズされました