GoogleスプレッドシートからAWS EC2インスタンスを起動する

中級

これはDevOps, Multimodal AI分野の自動化ワークフローで、8個のノードを含みます。主にSsh, Gmail, GoogleSheets, ScheduleTriggerなどのノードを使用。 Terraformを使用してGoogleスプレッドシートからAWS EC2インスタンスを起動

前提条件
  • Googleアカウント + Gmail API認証情報
  • Google Sheets API認証情報
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "id": "5T0q54z7XbP4rDKb",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "Launch AWS EC2 Instances from Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "7b6273c0-bbfc-4f5d-aecb-288b154300cc",
      "name": "ワークフロー概要",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        -860
      ],
      "parameters": {
        "width": 420,
        "height": 300,
        "content": "## 🚀 AWS EC2 Auto Launcher\n\n### Features:\n• Reads launch requests from Google Sheets\n• Launches EC2 instances via AWS API\n• Updates status in spreadsheet\n• Sends detailed confirmation emails\n• Error handling with notifications\n• Scheduled or manual execution\n\n### Triggers: Daily at 9 AM or Manual"
      },
      "typeVersion": 1
    },
    {
      "id": "b6c7b146-2815-4669-bdf0-f0cad7b7a0d7",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -980
      ],
      "parameters": {
        "color": 5,
        "width": 580,
        "height": 1140,
        "content": "### **`main.tf`**\n\n```hcl\n# Configure AWS provider\nprovider \"aws\" {\n  region  = var.aws_region\n  profile = var.aws_profile\n}\n\n# Create EC2 instance\nresource \"aws_instance\" \"example\" {\n  ami           = var.ami_id\n  instance_type = var.instance_type\n  key_name      = var.key_name\n\n  tags = {\n    Name = var.instance_name\n  }\n}\n\n# Output EC2 public IP\noutput \"ec2_public_ip\" {\n  value = aws_instance.example.public_ip\n}\n```\n\n---\n\n### **`variables.tf`**\n\n```hcl\nvariable \"aws_region\" {\n  description = \"AWS region to deploy in\"\n  type        = string\n}\n\nvariable \"aws_profile\" {\n  description = \"AWS CLI profile to use\"\n  type        = string\n  default     = \"default\"\n}\n\nvariable \"ami_id\" {\n  description = \"AMI ID for EC2 instance\"\n  type        = string\n}\n\nvariable \"instance_type\" {\n  description = \"EC2 instance type\"\n  type        = string\n  default     = \"t2.micro\"\n}\n\nvariable \"key_name\" {\n  description = \"SSH key pair name\"\n  type        = string\n}\n\nvariable \"instance_name\" {\n  description = \"EC2 instance Name tag\"\n  type        = string\n}\n```\n\n---\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "70087b97-5a6c-4a47-9c28-906f731d97ae",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        -860
      ],
      "parameters": {
        "color": 3,
        "width": 460,
        "height": 220,
        "content": "\n### **`terraform.tfvars`** (example values)\n\n```hcl\naws_region     = \"us-east-1\"\nami_id         = \"ami-0c55b159cbfafe1f0\"\ninstance_type  = \"t2.micro\"\nkey_name       = \"my-keypair\"\ninstance_name  = \"MyTerraformEC2\"\n```\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "55d7ea64-2ad7-4359-ba3c-0a589d29ce9c",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        500,
        -480
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ef286e0d-08f4-429c-b701-448406fb950d",
      "name": "インスタンス詳細の抽出",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        720,
        -480
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Launch_Requests",
          "cachedResultName": "Launch Requests"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_EC2_SHEET_ID",
          "cachedResultName": "EC2 Launch Requests"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "ScSS2KxGQULuPtdy",
          "name": "Google Sheets- test"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "b74895b0-b01a-4675-9af0-8cd256016576",
      "name": "EC2インスタンスの起動",
      "type": "n8n-nodes-base.ssh",
      "position": [
        940,
        -480
      ],
      "parameters": {
        "command": "=# Variables\nSERVER_USER=\"{{ $json.server_user }}\"\nSERVER_IP=\"{{ $json.server_ip }}\"\nWORKSPACE_NAME=\"{{ $json.workspace_name }}\"\nPWD=\"{{ $json.pwd }}\"\n\n# SSH and run Terraform commands\necho \"$PWD\" | ssh ${SERVER_USER}@${SERVER_IP} \"\n    cd /path/to/terraform/project &&\n    terraform workspace new ${WORKSPACE_NAME} || terraform workspace select ${WORKSPACE_NAME} &&\n    terraform init &&\n    terraform plan -out=tfplan &&\n    terraform apply -auto-approve tfplan\n\"",
        "authentication": "privateKey"
      },
      "credentials": {
        "sshPrivateKey": {
          "id": "ilPh8oO4GfSlc0Qy",
          "name": "SSH Password account - test "
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ee365181-a63b-4216-990b-ac2c5d721ea8",
      "name": "Googleシートの更新",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1160,
        -480
      ],
      "parameters": {
        "columns": {
          "value": {
            "ami_id": "={{ $json.ami_id }}",
            "region": "={{ $json.region }}",
            "key_pair": "={{ $json.key_pair }}",
            "public_ip": "={{ $json.public_ip }}",
            "timestamp": "={{ $now.toISO() }}",
            "private_ip": "={{ $json.private_ip }}",
            "instance_id": "={{ $json.instance_id }}",
            "project_name": "={{ $json.project_name }}",
            "instance_name": "={{ $json.instance_name }}",
            "instance_type": "={{ $json.instance_type }}",
            "launch_status": "={{ $json.launch_status }}",
            "instance_state": "={{ $json.instance_state }}",
            "reservation_id": "={{ $json.reservation_id }}",
            "security_group": "={{ $json.security_group }}",
            "requester_email": "={{ $json.requester_email }}",
            "availability_zone": "={{ $json.availability_zone }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Launch Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ami_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AMI ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "region",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Region",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "availability_zone",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Availability Zone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "private_ip",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Private IP",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "public_ip",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Public IP",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instance_state",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Instance State",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "key_pair",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Key Pair",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "security_group",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Security Group",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "project_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Project Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "requester_email",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Requester Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "launch_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Launch Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reservation_id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reservation ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow"
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "Launched_Instances",
          "cachedResultName": "Launched Instances"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_EC2_SHEET_ID",
          "cachedResultName": "EC2 Launch Requests"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "ScSS2KxGQULuPtdy",
          "name": "Google Sheets- test"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "61b4af75-72fd-4da6-a2ca-e3e9a16d928e",
      "name": "確認メールの送信",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1380,
        -480
      ],
      "webhookId": "949ecb7a-7e69-4348-adae-6299098bd08c",
      "parameters": {
        "sendTo": "={{ $json.requester_email }}",
        "message": "=<h2>🚀 EC2 Instance Launch Confirmation</h2><br><br><strong>Great news!</strong> Your EC2 instance has been launched successfully.<br><br><div style=\"background-color: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745;\"><h3>📋 Instance Details</h3><p><strong>Instance Name:</strong> {{ $json.instance_name }}<br><strong>Instance ID:</strong> <code>{{ $json.instance_id }}</code><br><strong>Instance Type:</strong> {{ $json.instance_type }}<br><strong>AMI ID:</strong> {{ $json.ami_id }}<br><strong>Region:</strong> {{ $json.region }}<br><strong>Availability Zone:</strong> {{ $json.availability_zone }}<br><strong>Current State:</strong> {{ $json.instance_state }}<br><strong>Key Pair:</strong> {{ $json.key_pair }}<br><strong>Security Group:</strong> {{ $json.security_group }}</p></div><br><div style=\"background-color: #e3f2fd; padding: 20px; border-radius: 8px; border-left: 4px solid #2196f3;\"><h3>🌐 Network Information</h3><p><strong>Private IP:</strong> {{ $json.private_ip }}<br><strong>Public IP:</strong> {{ $json.public_ip || 'Not assigned yet' }}</p></div><br><div style=\"background-color: #fff3e0; padding: 20px; border-radius: 8px; border-left: 4px solid #ff9800;\"><h3>📊 Additional Info</h3><p><strong>Launch Time:</strong> {{ $json.launch_time_aws }}<br><strong>Project:</strong> {{ $json.project_name }}<br><strong>Reservation ID:</strong> {{ $json.reservation_id }}<br><strong>Platform:</strong> {{ $json.platform }}<br><strong>Architecture:</strong> {{ $json.architecture }}</p></div><br><div style=\"background-color: #ffebee; padding: 15px; border-radius: 8px; border: 1px solid #f44336;\"><h4>⚠️ Important Notes</h4><ul><li>It may take a few minutes for the instance to be fully available</li><li>Public IP will be assigned once the instance is running</li><li>Remember to terminate the instance when no longer needed to avoid charges</li><li>You can connect using your key pair: <code>{{ $json.key_pair }}</code></li></ul></div><br><h3>🔗 AWS Console Link</h3><p><a href=\"https://{{ $json.region }}.console.aws.amazon.com/ec2/v2/home?region={{ $json.region }}#InstanceDetails:instanceId={{ $json.instance_id }}\" style=\"background-color: #007bff; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;\">View in AWS Console</a></p><br><p>If you have any questions or need assistance, please contact the infrastructure team.</p><br><p><em>This instance was launched automatically via n8n workflow.</em></p>",
        "options": {
          "ccList": "infrastructure@company.com"
        },
        "subject": "✅ AWS EC2 Instance Launched Successfully - {{ $json.instance_name }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PcTqvGU9uCunfltE",
          "name": "Gmail account - test"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "843e8aef-5fe8-413e-9a16-7c42b7575f7f",
  "connections": {
    "b74895b0-b01a-4675-9af0-8cd256016576": {
      "main": [
        [
          {
            "node": "ee365181-a63b-4216-990b-ac2c5d721ea8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ee365181-a63b-4216-990b-ac2c5d721ea8": {
      "main": [
        [
          {
            "node": "61b4af75-72fd-4da6-a2ca-e3e9a16d928e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "55d7ea64-2ad7-4359-ba3c-0a589d29ce9c": {
      "main": [
        [
          {
            "node": "ef286e0d-08f4-429c-b701-448406fb950d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ef286e0d-08f4-429c-b701-448406fb950d": {
      "main": [
        [
          {
            "node": "b74895b0-b01a-4675-9af0-8cd256016576",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級 - DevOps, マルチモーダルAI

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
中級
ノード数8
カテゴリー2
ノードタイプ5
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
Oneclick AI Squad

Oneclick AI Squad

@oneclick-ai

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34