プロキシ環境下で Visual Studio Code から Amazon Q Developer IDE を使用してみた
いわさです。
私は普段 Amazon Q Developer を使っているのですが、最近お客様からも Amazon Q Developer を使いたいというご相談を頂くことがあります。
組織で使用したい場合は IAM Identity Center と統合させることで組織管理下で Amazon Q Developer ユーザーのライセンスや使用状況を管理することが出来ます。
組織で使用する場合、プロキシ環境下で使う場合があります。
プロキシのモードにもよりますが、実は Amazon Q Developer IDE は明示的にプロキシの設定をしないと使用できない場合があります。
今回プロキシ環境下の Windows 環境に Visual Studio Code と Amazon Q 拡張をセットアップし、使ってみたのでその様子を紹介します。
検証用のプロキシ環境を用意
今回は VPC 上にパブリックサブネットとプライベートサブネットを用意し、パブリックサブネットにプロキシサーバー(Amazon Linux 2023 + Squid)を、プライベートサブネットに Windows クライアント(想定の Windows Server 2025)を用意します。
プライベートサブネットのルートテーブルは特に設定しませんのでインターネット通信ができない状態です。SSM の VPC エンドポイントを設定し、リモートアクセスします。次のような構成図に近いです。
プロキシサーバーの構築
Amazon Linux 2023 の EC2 を構築後に Squid をインストールします。
, #_
~\_ ####_ Amazon Linux 2023
~~ \_#####\
~~ \###|
~~ \#/ ___ https://aws.amazon.com/linux/amazon-linux-2023
~~ V~' '->
~~~ /
~~._. _/
_/ _/
_/m/'
[ec2-user@ip-10-0-10-165 ~]$ sudo dnf -y install squid
Amazon Linux 2023 Kernel Livepatch repository 160 kB/s | 17 kB 00:00
Dependencies resolved.
=========================================================================================================================================================================================
Package Architecture Version Repository Size
=========================================================================================================================================================================================
Installing:
squid x86_64 7:6.13-1.amzn2023.0.1 amazonlinux 3.5 M
:
Installed:
httpd-filesystem-2.4.62-1.amzn2023.noarch libecap-1.0.1-10.amzn2023.x86_64 libtool-ltdl-2.4.7-1.amzn2023.0.3.x86_64
perl-B-1.80-477.amzn2023.0.7.x86_64 perl-DBI-1.643-7.amzn2023.0.3.x86_64 perl-Data-Dumper-2.174-460.amzn2023.0.2.x86_64
perl-Digest-1.20-1.amzn2023.0.2.noarch perl-Digest-MD5-2.58-2.amzn2023.0.2.x86_64 perl-Digest-SHA-1:6.02-459.amzn2023.0.2.x86_64
perl-English-1.11-477.amzn2023.0.7.noarch perl-FileHandle-2.03-477.amzn2023.0.7.noarch perl-IO-Socket-IP-0.41-3.amzn2023.0.2.noarch
perl-Math-BigInt-1:1.9998.39-2.amzn2023.0.2.noarch perl-Math-BigRat-0.2624-500.amzn2023.0.2.noarch perl-Math-Complex-1.59-477.amzn2023.0.7.noarch
perl-URI-5.09-1.amzn2023.0.2.noarch perl-base-2.27-477.amzn2023.0.7.noarch perl-libnet-3.13-2.amzn2023.0.2.noarch
squid-7:6.13-1.amzn2023.0.1.x86_64
Complete!
インストールが完了しました。
バージョン確認と自動起動設定だけしておきます。
このままだと接続できないので後で直すのですが、一旦構成はデフォルトのままでいってみます。デフォルトの 3128 ポートで待機しているところまで確認しました。
[ec2-user@ip-10-0-10-165 ~]$ squid -v
Squid Cache: Version 6.13
Service Name: squid
This binary uses OpenSSL 3.2.2 4 Jun 2024. configure options: '--build=x86_64-amazon-linux-gnu' '--host=x86_64-amazon-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--libexecdir=/usr/lib64/squid' '--datadir=/usr/share/squid' '--sysconfdir=/etc/squid' '--with-logdir=/var/log/squid' '--with-pidfile=/run/squid.pid' '--disable-dependency-tracking' '--enable-eui' '--enable-follow-x-forwarded-for' '--enable-auth' '--enable-auth-basic=DB,fake,getpwnam,LDAP,NCSA,PAM,POP3,RADIUS,SASL,SMB,SMB_LM' '--enable-auth-ntlm=SMB_LM,fake' '--enable-auth-digest=file,LDAP' '--enable-auth-negotiate=kerberos' '--enable-external-acl-helpers=LDAP_group,time_quota,session,unix_group,wbinfo_group,kerberos_ldap_group' '--enable-storeid-rewrite-helpers=file' '--enable-cache-digests' '--enable-cachemgr-hostname=localhost' '--enable-delay-pools' '--enable-epoll' '--enable-icap-client' '--enable-ident-lookups' '--enable-linux-netfilter' '--enable-removal-policies=heap,lru' '--enable-snmp' '--enable-ssl' '--enable-ssl-crtd' '--enable-storeio=aufs,diskd,ufs,rock' '--enable-diskio' '--enable-wccpv2' '--disable-esi' '--enable-ecap' '--with-aio' '--with-default-user=squid' '--with-dl' '--with-openssl' '--with-pthreads' '--disable-arch-native' '--disable-security-cert-validators' '--disable-strict-error-checking' '--with-swapdir=/var/spool/squid' '--enable-translation' 'build_alias=x86_64-amazon-linux-gnu' 'host_alias=x86_64-amazon-linux-gnu' 'CC=gcc' 'CFLAGS=-O2 -ftree-vectorize -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'LDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/squid-6.13/.package_note-squid-6.13-1.amzn2023.0.1.x86_64.ld' 'CXX=g++' 'CXXFLAGS=-O2 -ftree-vectorize -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' 'LT_SYS_LIBRARY_PATH=/usr/lib64:'
[ec2-user@ip-10-0-10-165 ~]$ sudo systemctl enable squid
Created symlink /etc/systemd/system/multi-user.target.wants/squid.service → /usr/lib/systemd/system/squid.service.
[ec2-user@ip-10-0-10-165 ~]$ sudo systemctl restart squid
[ec2-user@ip-10-0-10-165 ~]$ sudo lsof -i:3128
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
squid 26158 squid 11u IPv6 43769 0t0 TCP *:squid (LISTEN)
クライアントの構築
続いてクライアントをプライベートサブネットを構築します。
今回は Windows 環境を想定し、Windows Server 2025 の AMI を選択しました。
このままだとプライベートサブネット上にリモート接続ができないので、SSM セッションマネージャーに必要な VPC エンドポイントだけ先に作成しました。
こちらの記事が参考になると思います。
RDP のポートフォワードなどが面倒だなと思ったので今回はフリートマネージャーから接続してみます。操作性が良いとは言えないですが、面倒な構成やクライアント設定が不要で接続できるのでちょっと接続してメンテナンスしたい時などに重宝しています。
クライアントの用意ができたら、インターネットアクセスできる確認してみましょう。
当然ながら、この時点ではまだインターネットにアクセスすることは出来ません。
今回は透過型プロキシではないので、クライアントからプロキシサーバーの明示的な指定が必要です。
ということでブラウザのプロキシ設定メニューから Windows のネットワーク設定を開きます。
ここでプロキシサーバーを指定します。
先ほど作成したパブリックサブネットのプライベート IP アドレスとデフォルトポートの 3128 を使います。
これでインターネットアクセスをもう一度試してみましょう。
Squid 経由で接続は試行していそうですが、Access Denied になりました。
プロキシサーバー側で拒否されていそうです。
プロキシサーバーの設定を変更
ということでプロキシサーバーの設定を見直してみましょう。
以前はデフォルトでも使えたような記憶もあるのですが、設定変更が必要なようです。
/etc/squid/squid.conf
を編集します。
[ec2-user@ip-10-0-10-165 ~]$ sudo vi /etc/squid/squid.conf
:
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# For example, to allow access from your local networks, you may uncomment the
# following rule (and/or add rules that match your definition of "local"):
http_access allow localnet
# And finally deny all other access to this proxy
http_access deny all
# Squid normally listens to port 3128
http_port 3128
:
デフォルトだとhttp_access allow localnet
がコメントアウトされていたのでここだけ有効化しました。
設定変更後、インターネット接続できることを確認しました。
Visual Studio Code + Amazon Q Developer のセットアップ
この状態で、Visual Studio Code と Amazon Q Developer のセットアップは出来るのでしょうか。
今回、前提としてプロキシサーバーでは特に特定外部サイトの遮断は行っていません。
試してみたところ、セットアップまでは出来ました。
まず Visual Studio Code のインストールは Web ブラウザから行うことが出来ます。
拡張機能「Amazon Q」の検索とインストールも可能でした。
そして Amazon Q へのサインインも可能です。
今回は IAM Identity Center の組織アカウントで Q Developer ユーザーを用意済みだったのでそちらでサインインしましたが、AWS Builder ID でも同様だと思います。
ブラウザでの認証・認可になるので、同様にうまくいくと思います。
ただし、試してみたところこの時点では Amazon Q Developer のチャット機能を使うことが出来ませんでした。
チャットモードもエージェントモードも同様で、問い合わせてみても最初は「Thinking...」になりますが、
しばらく経つと応答がなくなり、さらにもう少し待つと「connect ETIMEDOUT xx.xx.xx.xx:443」となりました。
エラーメッセージから、インターネット接続がうまく出来ていないような雰囲気を感じますね。良いですね。
プロキシ設定
ということでクライアントから明示的なプロキシサーバーの指定を行います。
Visual Studio Code の設定メニューから設定が可能です。
設定は Amazon Q Developer 専用の項目ではありません。
「Http: Proxy」という Visual Studio Code 共通の項目で設定します。
「http(s)://xx.xx.xx.xx:xxx」の形式で設定します。
今回はクライアントからプロキシサーバーの経路は HTTP で 3128 ポートです。
先ほどのプロキシサーバーのプライベート IP アドレスを指定して次のように指定します。(以下では誤って HTTPS で指定してしまっているのですが、HTTP が正しいです)
設定後、Amazon Q と再び対話してみると、今度は応答を得ることが出来ました。
さいごに
本日はプロキシ環境下で Visual Studio Code から Amazon Q Developer IDE を使用してみました。
Visual Studio Code の設定からプロキシ構成を行わないと Amazon Q Developer IDE の応答が得られないことが確認出来ました。
同様のエラーメッセージが発生した場合の原因のひとつとしてプロキシサーバーの設定が必要か覚えておくと良さそうです。
今回プロキシ環境を用意出来たので、同じ構成を使って Amazon Q Developer CLI や、あるいはプロキシサーバーをホワイトリスト運用している場合に必要な追加設定なども検証していってみます。