AWS IAM Role権限のポリシー

環境によってはIAMのフル権限がもらえないので、ロール周りの設定ができるポリシーを作成してアタッチしてもらう。 Resourceは適宜変更。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "iam:CreateInstanceProfile",
                "iam:DeleteInstanceProfile",
                "iam:List*",
                "iam:DeletePolicy",
                "iam:CreateRole",
                "iam:DeleteRole",
                "iam:AttachRolePolicy",
                "iam:PutRolePolicy",
                "iam:AddRoleToInstanceProfile",
                "iam:CreatePolicy",
                "iam:PassRole",
                "iam:Get*",
                "iam:DetachRolePolicy",
                "iam:DeleteRolePolicy"
            ],
            "Resource": "*"
        }
    ]
}

Terraform ElasticBeanstalkのアプリケーション HTTP 4xx ステータスコードを無視する設定

ConfigDocumentにルールを記載したJSONドキュメントを設定する必要がある。

  setting {
    namespace = "aws:elasticbeanstalk:healthreporting:system"
    name = "SystemType"
    value = "enhanced"
  }
  setting {
    namespace = "aws:elasticbeanstalk:healthreporting:system"
    name = "ConfigDocument"
    value = <<EOF
    {
    "Rules": {
      "Environment": {
        "Application": {
          "ApplicationRequests4xx": {
            "Enabled": false
          }
        }
      }
    },
    "Version": 1
    }
    EOF
  }

docs.aws.amazon.com

docs.aws.amazon.com

Terraform Elastic Beanstalk環境のsolution_stack_name一覧を取得する

Elastic Beanstalkの環境で指定可能なプラットフォーム一覧を取得する。

resource "aws_elastic_beanstalk_environment" "tfenvtest" {
  name                = "tf-test-name"
  application         = "${aws_elastic_beanstalk_application.tftest.name}"
  solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4" ← ここ
}

AWS CLI上から取得可能。regionとprofileは必要があれば指定する。

$ aws elasticbeanstalk list-available-solution-stacks --region="ap-northeast-1" --profile="hoge"

{
    "SolutionStacks": [
        "64bit Amazon Linux 2018.03 v4.8.3 running Node.js",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 5.4",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 5.5",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 5.6",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 7.0",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 7.1",
        "64bit Amazon Linux 2018.03 v2.8.9 running PHP 7.2",
        "64bit Amazon Linux 2018.03 v2.8.3 running Python 3.6",
        "64bit Amazon Linux 2018.03 v2.8.3 running Python 3.4",
        "64bit Amazon Linux 2018.03 v2.8.3 running Python",
        "64bit Amazon Linux 2018.03 v2.8.3 running Python 2.7",
        "64bit Amazon Linux 2018.03 v2.7.1 running Python 3.6",
        "64bit Amazon Linux 2017.03 v2.4.0 running Python 3.4",
        "64bit Amazon Linux 2016.09 v2.3.2 running Python 3.4",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.6 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.5 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.4 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.3 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.2 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.1 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.0 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 1.9.3",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.6 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.5 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.4 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.3 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.2 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.1 (Puma)",
        "64bit Amazon Linux 2018.03 v2.9.3 running Ruby 2.0 (Puma)",
        "64bit Amazon Linux 2017.09 v2.7.1 running Ruby 2.5 (Puma)",
        "64bit Amazon Linux 2017.09 v2.7.1 running Ruby 2.5 (Passenger Standalone)",
        "64bit Amazon Linux 2016.03 v2.1.3 running Ruby 2.3 (Passenger Standalone)",
        "64bit Amazon Linux 2016.03 v2.1.0 running Ruby 2.3 (Passenger Standalone)",
        "64bit Amazon Linux 2018.03 v3.1.3 running Tomcat 8.5 Java 8",
        "64bit Amazon Linux 2018.03 v3.1.3 running Tomcat 8 Java 8",
        "64bit Amazon Linux 2018.03 v3.1.3 running Tomcat 7 Java 7",
        "64bit Amazon Linux 2018.03 v3.1.3 running Tomcat 7 Java 6",
        "64bit Windows Server Core 2016 v2.0.3 running IIS 10.0",
        "64bit Windows Server 2016 v2.0.3 running IIS 10.0",
        "64bit Windows Server Core 2012 R2 v2.0.3 running IIS 8.5",
        "64bit Windows Server 2012 R2 v2.0.3 running IIS 8.5",
        "64bit Windows Server Core 2016 v1.2.0 running IIS 10.0",
        "64bit Windows Server 2016 v1.2.0 running IIS 10.0",
        "64bit Windows Server Core 2012 R2 v1.2.0 running IIS 8.5",
        "64bit Windows Server 2012 R2 v1.2.0 running IIS 8.5",
        "64bit Windows Server 2012 v1.2.0 running IIS 8",
        "64bit Windows Server 2008 R2 v1.2.0 running IIS 7.5",
        "64bit Windows Server Core 2012 R2 running IIS 8.5",
        "64bit Windows Server 2012 R2 running IIS 8.5",
        "64bit Windows Server 2012 running IIS 8",
        "64bit Windows Server 2008 R2 running IIS 7.5",
        "64bit Amazon Linux 2018.03 v2.12.11 running Docker 18.06.1-ce",
        "64bit Amazon Linux 2018.03 v2.13.0 running Multi-container Docker 18.06.1-ce (Generic)",
        "64bit Debian jessie v2.12.11 running Go 1.4 (Preconfigured - Docker)",
        "64bit Debian jessie v2.12.11 running Go 1.3 (Preconfigured - Docker)",
        "64bit Debian jessie v2.12.11 running Python 3.4 (Preconfigured - Docker)",
        "64bit Amazon Linux 2018.03 v2.8.3 running Java 8",
        "64bit Amazon Linux 2018.03 v2.8.3 running Java 7",
        "64bit Amazon Linux 2018.03 v2.11.1 running Go 1.12.4",
        "64bit Amazon Linux 2018.03 v2.6.9 running Packer 1.0.3",
        "64bit Amazon Linux 2018.03 v2.12.11 running GlassFish 5.0 Java 8 (Preconfigured - Docker)"
    ],
    "SolutionStackDetails": [
        {
            "SolutionStackName": "64bit Amazon Linux 2018.03 v4.8.3 running Node.js",
            "PermittedFileTypes": [
                "zip"
            ]
        },
        ...省略...
    ]
}

www.terraform.io

docs.aws.amazon.com

N日以前・以後から起動しているEC2インスタンス一覧を取得する

動作環境

30日以前に起動したインスタンスを取得する

DATE=`date -v-30d +%Y-%m-%d`; aws ec2 describe-instances --filter Name=instance-state-name,Values=running --query "Reservations[].Instances[?LaunchTime<=\`$DATE\`][].{id: InstanceId, type: InstanceType, launched: LaunchTime, tags: Tags}" 

100日以前にしたい場合はdate -v-30d +%Y-%m-%dの30を100に変更する。 filterのrunningstoppedに変えると停止中のインスタンス一覧を取得できる。

MySQL wargingsが発生した場合の確認方法

SHOW WARNINGS;

デフォルト表示数は64なので、変更したい場合はmax_error_countを変更する。

MySQL :: MySQL 5.6 リファレンスマニュアル :: 13.7.5.41 SHOW WARNINGS 構文