8
n8n 中文网amn8n.com

从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": "从Google Sheets启动AWS EC2实例",
  "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自动启动器"
      },
      "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`**"
      },
      "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": ""
      },
      "typeVersion": 1
    },
    {
      "id": "55d7ea64-2ad7-4359-ba3c-0a589d29ce9c",
      "name": "Google Sheets触发器",
      "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 Sheet",
      "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": {
    "Launch EC2 Instance": {
      "main": [
        [
          {
            "node": "Update Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Google Sheet": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Extract Instance Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Instance Details": {
      "main": [
        [
          {
            "node": "Launch EC2 Instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 开发运维, 多模态 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 查看

分享此工作流