# AWS Unresolved resource dependencies [AWSEBV2LoadBalancer] エラー

HTTP トラフィックを HTTPS にリダイレクトする際に yaml ファイル書きましたが、ELB デプロイ時テンプレートフォーマットエラーがでてデプロイ失敗しました。

Service:AmazonCloudFormation, Message:Template format error: Unresolved resource dependencies [AWSEBV2LoadBalancer] in the Resources block of the template

yaml の書き方

Type: AWS::ElasticLoadBalancingV2::ListenerRule
  Properties:
    LoadBalancerArn:
      Ref: AWSEBV2LoadBalancer
    Port: 80
    Protocol: HTTP
    DefaultActions:
      - Type: redirect
        RedirectConfig:
          Host: "#{host}"
          Path: "/#{path}"
          Port: "443"
          Protocol: "HTTPS"
          Query: "#{query}"
          StatusCode: "HTTP_301"

AWS::ElasticLoadBalancingV2::ListenerRule (opens new window)

# Apache サーバーでリダイレクト

仮想ホストファイル設定を変更することでリダイレクト方法

/etc/httpd/conf/httpd.conf

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
</VirtualHost>

.htaccess ファイル編集してリダイレクトする方法

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

仮想ホストファイルで.htaccess 利用許可が必要



 



<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Apache 再起動

# Nginx でリダイレクト

nginx.conf

server {
    listen 80;
    server_name _;
    if ($http_x_forwarded_proto = 'http'){
    return 301 https://$host$request_uri;
    }
}

nginx 再起動

# http から https のリダイレクトはサーバー側で行うべき

本番では問題なく動いてるんものが開発環境でデプロイエラーはやはり環境依存設定があったからです。ロードバランサーの設定ファイルは.ebextensions に書くべきではないでしょう

nginx でリダイレクトするように書き換えました。

.platform/nginx/conf.d/redirect.conf

server {
    listen 80;
    rewrite ^ https://$host$request_uri permanent;
}
2021-11-12
  • server
  • aws

関連記事

ジェネレーティブ AI と大規模言語モデル(LLM)を学ぶためのリソース
XZ Utils 事件対応
Ubuntu で Web サーバーを構築する手順
メールサーバー移行と POP & IMAP 設定
Docker Supervisor 使ってバッチ処理
よく使う WSL コマンド
自宅サーバー構築!  Nextcloud で NAS クラウドストレージ
no such file or directory: /usr/share/zsh/vendor-completions/_docker
oh my zsh 使うべし
AWS Lambda Nodejs で chatwork へ post 送信
AWS CloudWatch ログ監視で Lambda 処理
AWS SES メール開封確認  DB に集計
Vim 操作とショートカット
DDNS 無料ダイナミック DNS サービス 4 つ
Nginx 基本設定
SPF メール送信なりすまし対策
Windows Mac Linux hosts ファイル場所
ディスク容量を確認する df コマンド
Laravel Address already in use の原因
content-security-policy 設定
AWS Elastic Beanstalk php.ini 設定変更
AWS Elastic Beanstalk 環境設定
AWS のタイムゾーンを UTC 協定世界時から JST 日本標準時に変更
Docker の基本的な使い方
Amazon DynamoDB 制限調査
AWS 504 Gateway Timeout エラー対応
Shell と Bash のいろいろ
Mac ターミナル SSH 接続設定
Elastic Beanstalk \$\SERVER['REMOTEADDR'] 取得できない
crontab 設定いろいろ
AWS EC2 の amazon-linux-extras の話
デプロイツール Capistrano
解決! xserver php バージョンアップした時に ssh 環境に反映されない
youtube 見れるように vpn サーバー建ててみた
xserver に vim インストール
xserver に nodejs インストール
レンタルサーバーなら xserver おすすめ理由
Docker command でドッカー練習する時のメモ
Windows10 Home に Docker 入れた時のメモ
Centos7 Webserver 構築の時のメモ