Systems Manager 実務Tips
Systems Manager 実務Tips
Section titled “Systems Manager 実務Tips”AWS CLI
Section titled “AWS CLI”# Parameter Store(パラメータ作成)aws ssm put-parameter \ --name /myapp/prod/db-password \ --value "MySecretPassword123" \ --type SecureString \ --key-id alias/aws/ssm
# パラメータ取得aws ssm get-parameter \ --name /myapp/prod/db-password \ --with-decryption
# Run Command実行aws ssm send-command \ --document-name "AWS-RunShellScript" \ --targets "Key=tag:Environment,Values=prod" \ --parameters 'commands=["sudo yum update -y"]'
# Session Manager起動aws ssm start-session --target i-1234567890abcdef0Parameter Store使用例(Python)
Section titled “Parameter Store使用例(Python)”import boto3
ssm = boto3.client('ssm')
# パラメータ取得response = ssm.get_parameter( Name='/myapp/prod/db-password', WithDecryption=True)password = response['Parameter']['Value']
# 複数パラメータ取得response = ssm.get_parameters_by_path( Path='/myapp/prod/', Recursive=True, WithDecryption=True)for param in response['Parameters']: print(f"{param['Name']}: {param['Value']}")ベストプラクティス
Section titled “ベストプラクティス”セキュリティ: - Session Manager使用(SSH不要) - SecureString for secrets - IAM最小権限
運用: - Maintenance Windows設定 - 段階的パッチ適用 - CloudWatch統合
コスト: - Standard Parameter Store(無料) - 不要なAutomation削減トラブルシューティング
Section titled “トラブルシューティング”# コマンド履歴確認aws ssm list-commands
# コマンド結果確認aws ssm get-command-invocation \ --command-id xxxxx \ --instance-id i-xxxxx