8
n8n 中文网amn8n.com

通过电子邮件管理AWS IAM用户

中级

这是一个DevOps, Multimodal AI领域的自动化工作流,包含 13 个节点。主要使用 Code, AwsIam, Switch, EmailSend, EmailReadImap 等节点。 通过电子邮件命令自动化AWS IAM用户管理

前置要求
  • AWS Access Key 和 Secret
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "CIJpDmGwbF9xSHqc",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "通过电子邮件管理 AWS IAM 用户",
  "tags": [],
  "nodes": [
    {
      "id": "6a3a0d65-00c8-4760-aef1-778dc216a38b",
      "name": "从电子邮件中提取数据",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        920
      ],
      "parameters": {
        "jsCode": "const emailBody = $json[\"textPlain\"] || \"\";\n\n// Helper function to match patterns\nfunction matchFirst(patterns) {\n  for (const pattern of patterns) {\n    const match = emailBody.match(pattern);\n    if (match) return match[1];\n  }\n  return null;\n}\n\n// Detect user name\nconst userName = matchFirst([\n  /user[:\\s*]*([a-zA-Z0-9._-]+)/i,\n  /username\\s+([a-zA-Z0-9._-]+)/i\n]);\n\n// Detect group name\nconst groupName = matchFirst([\n  /group[:\\s*]*([a-zA-Z0-9._-]+)/i,\n  /groupname\\s+([a-zA-Z0-9._-]+)/i\n]);\n\n// Decide task type\nlet task_type = null;\nif (/create user/i.test(emailBody)) task_type = \"create_user\";\nelse if (/delete user/i.test(emailBody)) task_type = \"delete_user\";\nelse if (/add user to group/i.test(emailBody)) task_type = \"add_user_to_group\";\nelse if (/get user$/i.test(emailBody)) task_type = \"get_user\";\nelse if (/get many users/i.test(emailBody)) task_type = \"get_many_users\";\nelse if (/remove user from group/i.test(emailBody)) task_type = \"remove_user_from_group\";\nelse if (/update user/i.test(emailBody)) task_type = \"update_user\";\n\nreturn [\n  {\n    json: {\n      userName,\n      groupName,\n      task_type\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
      "name": "制作电子邮件内容",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        920
      ],
      "parameters": {
        "jsCode": "const taskType = $json.task_type || \"\";\nconst userName = $json.userName || \"\";\nconst groupName = $json.groupName || \"\";\nconst status = $json.status || \"\"; // \"success\" or \"fail\"\nconst errorMsg = $json.error || \"\";\n\n// Create readable task name\nconst taskMap = {\n  create_user: \"Create User\",\n  delete_user: \"Delete User\",\n  add_user_to_group: \"Add User to Group\",\n  get_user: \"Get User\",\n  get_many_users: \"Get Many Users\",\n  remove_user_from_group: \"Remove User from Group\",\n  update_user: \"Update User\"\n};\n\nlet message = \"\";\n\nif (status === \"success\") {\n  message = `✅ ${taskMap[taskType] || \"Task\"} completed successfully.\\n`;\n  if (userName) message += `User: ${userName}\\n`;\n  if (groupName) message += `Group: ${groupName}\\n`;\n} else {\n  message = `❌ ${taskMap[taskType] || \"Task\"} failed.\\n`;\n  if (userName) message += `User: ${userName}\\n`;\n  if (groupName) message += `Group: ${groupName}\\n`;\n  if (errorMsg) message += `Error: ${errorMsg}\\n`;\n}\n\nreturn {\n  json: {\n    subject: `${status === \"success\" ? \"Success\" : \"Failure\"} - ${taskMap[taskType] || \"IAM Task\"}`,\n    body: message\n  }\n};\n"
      },
      "typeVersion": 2
    },
    {
      "id": "798b73f3-92d4-43ad-9f3b-1221f885c7b1",
      "name": "发送电子邮件回复",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1100,
        920
      ],
      "webhookId": "9be96438-96fa-48c1-8cea-75c179322fb3",
      "parameters": {
        "text": "={{$json[\"message\"]}}",
        "options": {
          "replyTo": "={{ $('GET Email Request').item.json.from }}"
        },
        "subject": "={{$json[\"subject\"]}}",
        "toEmail": "={{ $('GET Email Request').item.json.from }}",
        "fromEmail": "abc@gmail.com",
        "emailFormat": "text"
      },
      "credentials": {
        "smtp": {
          "id": "G1kyF8cSWTZ4vouN",
          "name": "SMTP -test"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f38dc5ba-90e8-41c3-bc73-c2efcbf9ceaf",
      "name": "创建用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        320
      ],
      "parameters": {
        "userName": "={{ $json.username }}",
        "operation": "create",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f8f3a743-d919-49ad-ba78-9873dd034e8f",
      "name": "删除用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        520
      ],
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "userName",
          "value": "={{ $json.username }}"
        },
        "operation": "delete",
        "requestOptions": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "be25ba9c-2362-43d4-a670-d98a39515130",
      "name": "将用户添加到组",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        720
      ],
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "userName",
          "value": "={{ $json.username }}"
        },
        "group": {
          "__rl": true,
          "mode": "groupName",
          "value": "={{ $json.groupname }}"
        },
        "operation": "addToGroup",
        "requestOptions": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2dc04cc3-224f-433b-bada-f04584f57321",
      "name": "获取用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        920
      ],
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "userName",
          "value": "={{ $json.username }}"
        },
        "operation": "get",
        "requestOptions": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "198b262e-fe75-454b-9609-b84a824a0880",
      "name": "获取多个用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        1120
      ],
      "parameters": {
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3bd5fda6-0669-4dd0-a15b-5fb10ee23bd2",
      "name": "从组中移除用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        1320
      ],
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "userName",
          "value": "={{ $json.username }}"
        },
        "group": {
          "__rl": true,
          "mode": "groupName",
          "value": "={{ $json.groupname }}"
        },
        "operation": "removeFromGroup",
        "requestOptions": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "dbc30150-ccb6-492f-b956-e86da72dcf6c",
      "name": "更新用户",
      "type": "n8n-nodes-base.awsIam",
      "position": [
        660,
        1520
      ],
      "parameters": {
        "user": {
          "__rl": true,
          "mode": "userName",
          "value": "={{ $json.username }}"
        },
        "userName": "={{ $json.newusername }}",
        "operation": "update",
        "requestOptions": {},
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "id": "KRRqQf7ufs26Mvaq",
          "name": "AWS account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d0635da5-3ac9-494c-944a-e3352dcaa685",
      "name": "获取电子邮件请求",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        0,
        920
      ],
      "parameters": {
        "options": {
          "customEmailConfig": "[\"UNSEEN\", [\"SUBJECT\", \"iam\"]]"
        }
      },
      "credentials": {
        "imap": {
          "id": "zTEGYssr7MSVeCs3",
          "name": "IMAP-test"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "53281026-4fc1-40d8-834a-1085e049f011",
      "name": "检查任务类型",
      "type": "n8n-nodes-base.switch",
      "position": [
        440,
        836
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "99e9f0b2-e19b-45c5-a60e-317d772e6291",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "{{ json.task_type}}",
                    "rightValue": "create_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "4e72b4c7-eed9-4039-84c7-773a4dee2eb6",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type}}",
                    "rightValue": "delete_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "aef1b8b8-9175-4819-9cb8-87209e4b2954",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type}}",
                    "rightValue": "add_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a256941b-0882-4ee1-9126-491da78f5fb4",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type.}}",
                    "rightValue": "get_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a502de56-2efa-4766-b883-65d8cefaab1a",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type}}",
                    "rightValue": "get_many_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "62aae8fd-71f2-4194-af78-b8d42179a2d0",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type}}",
                    "rightValue": "remove_user"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e70fb51d-7d2e-4ed2-bdde-7edd03059033",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ json.task_type}}",
                    "rightValue": "update_user"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "32ac6b9c-62b5-4493-9f8d-d0de9fca4211",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        520
      ],
      "parameters": {
        "color": 5,
        "width": 680,
        "height": 340,
        "content": "## 工作原理"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a67ad521-0006-4818-a40d-8cc3d753bdb9",
  "connections": {
    "2dc04cc3-224f-433b-bada-f04584f57321": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f38dc5ba-90e8-41c3-bc73-c2efcbf9ceaf": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f8f3a743-d919-49ad-ba78-9873dd034e8f": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "dbc30150-ccb6-492f-b956-e86da72dcf6c": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "198b262e-fe75-454b-9609-b84a824a0880": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "be25ba9c-2362-43d4-a670-d98a39515130": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d0635da5-3ac9-494c-944a-e3352dcaa685": {
      "main": [
        [
          {
            "node": "6a3a0d65-00c8-4760-aef1-778dc216a38b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "53281026-4fc1-40d8-834a-1085e049f011": {
      "main": [
        [
          {
            "node": "f38dc5ba-90e8-41c3-bc73-c2efcbf9ceaf",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "f8f3a743-d919-49ad-ba78-9873dd034e8f",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "be25ba9c-2362-43d4-a670-d98a39515130",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "2dc04cc3-224f-433b-bada-f04584f57321",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "198b262e-fe75-454b-9609-b84a824a0880",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "3bd5fda6-0669-4dd0-a15b-5fb10ee23bd2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "dbc30150-ccb6-492f-b956-e86da72dcf6c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "aa61fe8f-53f3-4f5f-bdcf-a7c439586215": {
      "main": [
        [
          {
            "node": "798b73f3-92d4-43ad-9f3b-1221f885c7b1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3bd5fda6-0669-4dd0-a15b-5fb10ee23bd2": {
      "main": [
        [
          {
            "node": "aa61fe8f-53f3-4f5f-bdcf-a7c439586215",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6a3a0d65-00c8-4760-aef1-778dc216a38b": {
      "main": [
        [
          {
            "node": "53281026-4fc1-40d8-834a-1085e049f011",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 开发运维, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量13
分类2
节点类型6
难度说明

适合有一定经验的用户,包含 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