投稿

7月, 2024の投稿を表示しています

linux aws configure コマンドで設定

 ・awsコマンドをインストール後、以下を実行で設定できる。 # リージョンに us-east-1 指定 $ aws configure set region us-east-1 # output に text を指定 $ aws configure set output text # アクセスキーを指定 $ aws configure set aws_access_key_id xxxx # シークレットキーを指定 $ aws configure set aws_secret_access_key yyyy

AWS Cloudformation パスワードのみ シークレット 作成

 ・パスワードのみのシークレットをCloudformationで作成するテンプレートを示す。 ・パスワードは p@ssw0rd とする。 Resources:   TestSecret:     Type: 'AWS::SecretsManager::Secret'     Properties:       SecretString:  "p@ssw0rd"       Name: "testSecret"

AWS Cloudformation VPC Endpoint DNS名 取得

 ・GetAttでVPCendpointのDNS名(アベイラビリティーゾーンなし)を取得する ・VPC Endpoint例 TestEndpoint:     Type: AWS::EC2::VPCEndpoint     Properties:       SecurityGroupIds:         - !Ref VPCEndpointSecurityGroup       ServiceName: !Sub com.amazonaws.${AWS::Region}.ssm       SubnetIds:         - !Ref Subnet001       VpcEndpointType: Interface       VpcId: !Ref VPC ・以下で取得できる。 Value: !Select ['1', !Split [':', !Select ['0', !GetAtt TestEndpoint.DnsEntries]]] 参考 AWS::EC2::VPCEndpoint

AWS Cloudformation GetAtt Managed AD DNS IPアドレス 取得

 ・Managed ADのDNS IPアドレスをGetAttで取得する。 ・Managed AD作成例   TestDirectory:     Type: AWS::DirectoryService::MicrosoftAD     Properties:       Edition: Standard       Name: example.com       Password: !Ref DirectoryPassword       VpcSettings:         SubnetIds:           - !Ref PublicSubnet0           - !Ref PublicSubnet1         VpcId:           !Ref Vpc ・GetAttで取得 ★GetAttで取得できる情報は以下URLに記載。 ★Typeでぐぐるとヒットする(今回だと AWS::DirectoryService::MicrosoftAD) AWS::DirectoryService::MicrosoftAD ・DNSは配列 ・引用(上記URLより) DnsIpAddresses The IP addresses of the DNS servers for the directory, such as [ "192.0.2.1", "192.0.2.2" ]. DNSs: !GetAtt TestDirectory.DnsIpAddresses ・一つずつ取得するには Selectと組み合わせる。 DNS1: !Select [0, !GetAtt TestDirectory.DnsIpAddresses] DNS2: !Select [1, !GetAtt TestDirectory.DnsIpAddresses]

AWS Cloudformation EC2 linux Managed AD 起動時 シームレス参加

 以下の手順をベースにCloudformation化できる。 Amazon EC2 Linux インスタンスを AWS Managed Microsoft AD Active Directory にシームレスに結合する ■事前準備 ・Managed AD構築済(DHCPセット済)      参考       【CloudFormation】AWS Managed Microsoft AD + DHCPOptionSet を構築する cfn テンプレートを書いてみた ・セッションマネージャー経由でEC2にアクセス可であること。 ★Cloudformationテンプレートのポイント 1. ADのAdminのシークレット作成(セキュリティ上よろしくないが。。。)  ※以下赤字を変更すると、正常に動作しなくなる(d-xxxxxxxxx はディレクトリID指定。) Resources:   ManagedADSecret:     Type: AWS::SecretsManager::Secret     Properties:       Name: aws/directory-services/ d-xxxxxxxxx /seamless-domain-join       Description: Secret for Managed AD credentials       SecretString: '{" awsSeamlessDomainUsername ": "Admin", " awsSeamlessDomainPassword ": "<AdminのPassword>"}' 2. Secrets Manager の IAM 読み取りポリシーを作成 赤字は「1.」で作成したシークレット   SecretsManagerPolicy:     Type: AWS::IAM::Policy     Properties:       PolicyName: ...

AWS Cloudformation ImportValue Sub 併用

 ImportValue単体は以下で指定。 以下はSubnetIdに 他スタックで出力したExport名 Subnet001を指定。 SubnetId: !ImportValue Subnet001 ★ImportValue + Sub は以下で指定。 以下はRoleNameに 他スタックで出力したExport名 Test001と文字列を結合して指定。 RoleName: !Sub - "${Test001}-role" - Test001: !ImportValue Test001 Test001が abc の場合、 RoleName は abc-role となる。

AWS Cloudformation EC2 linux UserData 小ネタ

以下例はインデントのズレがある可能性があるため、確認要。 以下はlinux起動時にechoを実行する(基本形)  Userdata:     Fn::Base64: |         #!/bin/bash         echo "test" Userdata + Sub。 Cloudformationテンプレート内で定義した値指定。 SubnetId は事前に定義してあるとする。 以下はSubnetIdの値がechoされる。 Userdata:     Fn::Base64: !Sub       |         #!/bin/bash         echo "${SubnetId}" シェル変数を使用する。 以下はechoで sample の文字列を出力。 Userdata:     Fn::Base64: !Sub         |          #!/bin/bash          TEST1="sample"          echo "${!TEST1}" Userdataに引数を与える。 SubnetId は事前に定義してあるとする。 以下はSubnet1(SubnetId)の値がechoされる。 Userdata:     Fn::Base64: !Sub         - |            #!/bin/bash            echo "${Subnet1}"         -  {       ...

linux シェルスクリプト cron 設定 crontab -e を使わず

 crontab -e を使わず、設定する。 以下は1分おきにlsする設定。 設定後、crontab -l で設定されていることを確認できるはず。 echo "*/1 * * * * ls" | crontab -

AWS CLI プライベートサブネット(Private Subet) Storage Gateway File Gateway AD

■事前準備  ・①Storage Gateway用EC2作成済      →セキュリティグループで80ポート許可  ・②Storage Gateway VPCエンドポイント作成済  ・③AWS CLIコマンド実行用EC2      →Storage Gateway用EC2と同じプライベートサブネットに配置済      →AWS CLIが実行できるようにaws configure設定済  ・④S3作成  ・⑤Storage Gateway ファイル共有-S3アクセス用 IAMRole作成 ※詳細や不足があれば以下を参照 AWS Storage Gateway(VPC エンドポイントあり)環境をCLIで構築し運用する手順 ■概要 1. ゲートウェイのアクティベーションキーを取得 2. ゲートウェイのアクティベーション 3. ローカルディスク設定 4. ゲートウェイをAD参加 5. File Gateway - ファイル共有設定(SMB) ■詳細 ※以下手順は③から実行する 1. ゲートウェイのアクティベーションキーを取得  ・curlで取得       curl "http://gateway_ip_address/?gatewayType=gateway_type&activationRegion=region_code&vpcEndpoint=vpc_endpoint&no_redirect" 詳細は以下参考 Storage Gateway on EC2 を使うためのアクティベーションキーを取得する方法 2. ゲートウェイのアクティベーション 3. ローカルディスク設定 詳細は以下参考 AWS Storage Gateway(VPC エンドポイントあり)環境をCLIで構築し運用する手順 4. ゲートウェイをAD参加 join-domain ¥ --gateway-arn <「2.」でアクティベーションしたゲートウェイのARN> ¥ --domain-name <参加させた...

linux シェルスクリプト ユーザパスワード 設定

以下はlocaluserのパスワードをp@ssw0rdに設定  #!/bin/aash sudo echo "p@ssw0rd" | passwd --stdin localuser

linux シェルスクリプト while 一定時間後 終了

 以下は15分経過後、whileループ終了する #!/bin/sh END_TIME=$(date -d '+15 min' '+%s') while [ $(echo "$END_TIME - $(date '+%s')" | bc) -ge 0 ] do #ループ処理 done