0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EC2のproxy設定をSSM(RunCommand)と同期

Posted at

複数台のEC2を持っていて、http_proxyやno_proxy設定(に限らず)をSSM パラメータストアで管理している値を同期したい。
例として、パラメータストアに、http_proxy,https_proxy,no_proxyを登録して、パラメータストアの内容を変更した後、EC2の/etc/environmentも同期したいシーンとして、以下のようなRunCommandを発行します。

ドキュメント名:AWS-RunShellScript
コマンドパラメータ:以下

#!/bin/bash
## get parameter from parameter-store
http_proxy=$(aws ssm --region ap-northeast-1 get-parameter --name http_proxy --query "Parameter.Value" --output text)
https_proxy=$(aws ssm --region ap-northeast-1 get-parameter --name https_proxy --query "Parameter.Value" --output text)
no_proxy=$(aws ssm --region ap-northeast-1 get-parameter --name no_proxy --query "Parameter.Value" --output text)

## debug vars
echo http_proxy is ${http_proxy}
echo https_proxy is ${https_proxy}
echo no_proxy is ${no_proxy}

## show env before sync
cat /etc/environment

## re-sync env
sed -i -e '2,$d' /etc/environment
cat /etc/environment
echo "http_proxy=${http_proxy}" >> /etc/environment
echo "https_proxy=${https_proxy}" >> /etc/environment
echo "no_proxy=${no_proxy}" >> /etc/environment

## show env after sync
cat /etc/environment
  • ターゲットのEC2はubuntu 20.04 LTSで確認
  • 全てのミドルウェアが/etc/environmentを参照するわけではないので、/etc/environment以外に必要となる設定ファイルへの反映するコードが必要です
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?