{
  "id": "0mnXbzHdP3r7Uk5p",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI-Powered AWS S3 Manager with Audit Logging in n8n (Slack/ChatOps Workflow)",
  "tags": [
    {
      "id": "zVkByIt5M465W2a8",
      "name": "aws",
      "createdAt": "2025-09-12T06:14:33.823Z",
      "updatedAt": "2025-09-12T06:14:33.823Z"
    }
  ],
  "nodes": [
    {
      "id": "e61c5d1b-7c6a-486a-b7ab-8af828dfb2e1",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -160,
        736
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "198007d2-5b4f-449e-8e6b-b54c76bf394a",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -32,
        736
      ],
      "parameters": {
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "b57e9ec2-dd1d-496d-947f-40f1c18e5506",
      "name": "AWS S3 Manager Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        280,
        512
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an intelligent assistant for managing AWS S3 via natural language.\n\nYou are equipped with 7 tools:\n\n1. ListBuckets \u2014 to list all available S3 buckets.\n2. ListObjects \u2014 to list files in a specific bucket or prefix.\n3. CopyObject \u2014 to copy a file from one bucket/key to another.\n4. DeleteObject \u2014 to delete a file from an S3 bucket.\n5. ListFolders \u2014 to list top-level folders using S3 prefixes.\n6. CreateFolder \u2014 to create a new folder using a zero-byte object with a trailing slash.\n7. AddAuditLog \u2014 to log all tool calls to Google Sheets (via appendOrUpdate: sheet).\n\nYour responsibilities:\n\n- Parse user requests, determine intent, and call the appropriate S3 tool.\n- Immediately after executing **any of the first 6 tools**, you **must call the `AddAuditLog` tool** with full context.\n- **Do NOT call AddAuditLog** if:\n  - You didn\u2019t call any operational tool\n  - The tool being executed is already `AddAuditLog` (to avoid loops)\n\n---\n\n### The audit log entry (AddAuditLog) should include:\n\n```json\n{\n  \"timestamp\": \"<UTC timestamp>\",\n  \"tool\": \"<ToolName used>\",\n  \"parameters\": { /* tool call parameters */ },\n  \"status\": \"success\",\n  \"user\": {\n    \"name\": \"<if available>\",\n    \"source\": \"<e.g., Slack, Telegram>\"\n  },\n  \"chat_prompt\": \"<original user message>\",\n  \"tool_call_reasoning\": \"<why this tool was chosen>\"\n}"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d8acd9a1-bd45-4953-82ae-bb27ef449011",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -384,
        512
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "28fc7970-7fd7-44b3-bf4e-1281c322bb65",
      "name": "Get many buckets in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        96,
        736
      ],
      "parameters": {
        "resource": "bucket",
        "operation": "getAll",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "ddea4199-a84f-4c66-8764-18bb609ec4e7",
      "name": "Get many files in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        224,
        736
      ],
      "parameters": {
        "options": {},
        "operation": "getAll",
        "returnAll": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Return_All', ``, 'boolean') }}",
        "bucketName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Bucket_Name', ``, 'string') }}"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "faf57b94-3073-47e6-ac88-5203fb2d9ad6",
      "name": "Copy a file in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        352,
        736
      ],
      "parameters": {
        "operation": "copy",
        "sourcePath": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Source_Path', ``, 'string') }}",
        "destinationPath": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Destination_Path', ``, 'string') }}",
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2099f8fa-d295-47f3-a014-2d22b35f4676",
      "name": "Delete a file in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        480,
        736
      ],
      "parameters": {
        "fileKey": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('File_Key', ``, 'string') }}",
        "options": {},
        "operation": "delete",
        "bucketName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Bucket_Name', ``, 'string') }}"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0b5fc6f0-43e2-4000-b58e-6ffe240d99bf",
      "name": "Get many folders in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        608,
        736
      ],
      "parameters": {
        "options": {},
        "resource": "folder",
        "operation": "getAll",
        "returnAll": "",
        "bucketName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Bucket_Name', ``, 'string') }}"
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "71afb290-a9e8-4ac7-bf02-09687ab630cd",
      "name": "Create a folder in AWS S3",
      "type": "n8n-nodes-base.awsS3Tool",
      "position": [
        736,
        736
      ],
      "parameters": {
        "resource": "folder",
        "bucketName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Bucket_Name', ``, 'string') }}",
        "folderName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Folder_Name', ``, 'string') }}",
        "additionalFields": {}
      },
      "credentials": {
        "aws": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "046374dc-9b0f-460a-85a6-5e53ba2648d4",
      "name": "Append or update row in sheet in Google Sheets",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        864,
        736
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aaDJ9ZAt2LLpZDFcXjVaYW57JwyruCrl5UJWejG1ZTk/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1aaDJ9ZAt2LLpZDFcXjVaYW57JwyruCrl5UJWejG1ZTk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aaDJ9ZAt2LLpZDFcXjVaYW57JwyruCrl5UJWejG1ZTk/edit?usp=drivesdk",
          "cachedResultName": "AWS S3 Audit Logs"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "df1923d0-a7b5-44a4-808e-380d4784b007",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -96
      ],
      "parameters": {
        "color": 6,
        "width": 832,
        "height": 1856,
        "content": "# AI-Powered AWS S3 Manager with Audit Logging in n8n (Slack/ChatOps Workflow)\n> This n8n workflow empowers users to manage AWS S3 buckets and files using natural language via Slack or chat platforms. Equipped with an OpenAI-powered Agent and integrated audit logging to Google Sheets, it supports operations like listing buckets, copying/deleting files, managing folders, and automatically records every action for compliance and traceability.\n## \ud83d\udc65 Who\u2019s it for\nThis workflow is built for:\n- DevOps engineers who want to manage AWS S3 using natural chat commands.\n- Technical support teams interacting with AWS via Slack, Telegram, etc.\n- Automation engineers building ChatOps tools.\n- Organizations that require **audit logs** for every cloud operation.\n\nUsers don\u2019t need AWS Console or CLI access \u2014 just send a message like \u201cCopy file from dev to prod\u201d.\n## \u2699\ufe0f How it works / What it does\nThis workflow turns natural chat input into **automated AWS S3 actions** using an OpenAI-powered AI Agent in n8n.\n### \ud83d\udd01 Workflow Overview:\n1. **Trigger**: A user sends a message in Slack, Telegram, etc.\n2. **AI Agent**: \n   - Interprets the message\n   - Calls one of 6 S3 tools:\n     - `ListBuckets`\n     - `ListObjects`\n     - `CopyObject`\n     - `DeleteObject`\n     - `ListFolders`\n     - `CreateFolder`\n3. **S3 Action**: Performs the requested AWS S3 operation.\n4. **Audit Log**: Logs the tool call to Google Sheets using `AddAuditLog`:\n   - Includes timestamp, tool used, parameters, prompt, reasoning, and user info.\n\n## \ud83d\udee0\ufe0f How to set up\n### Step-by-step Setup:\n1. **Webhook Trigger**\n   - Slack, Telegram, or custom chat platform \u2192 connects to n8n.\n\n2. **OpenAI Agent**\n   - Model: `gpt-4` or `gpt-3.5-turbo`\n   - Memory: Simple Memory Node\n   - Prompt: Instructs agent to always follow tool calls with an `AddAuditLog` call.\n\n3. **AWS S3 Nodes**\n   - Configure each tool with AWS credentials.\n   - Tools:\n     - `getAll: bucket`\n     - `getAll: file`\n     - `copy: file`\n     - `delete: file`\n     - `getAll: folder`\n     - `create: folder`\n\n4. **Google Sheets Node**\n   - Sheet: `AWS S3 Audit Logs`\n   - Operation: `Append or Update Row`\n   - Columns (must match input keys):  \n     - `timestamp`, `tool`, `status`, `chat_prompt`, `parameters`, `user_name`, `tool_call_reasoning`\n\n5. **Agent Tool Definitions**\n   - Include `AddAuditLog` as a 7th tool.\n   - Agent calls it **immediately after every S3 action** (except when logging itself).\n\n## \u2705 Requirements\n- [ ] n8n instance with AI Agent feature\n- [ ] OpenAI API Key\n- [ ] AWS IAM user with S3 access\n- [ ] Google Sheet with required columns\n- [ ] Chat integration (Slack, Telegram, etc.)\n\n## \ud83e\udde9 How to customize the workflow\n| Feature              | Customization Tip                                            |\n|----------------------|--------------------------------------------------------------|\n| \ud83c\udf0e Multi-region S3   | Let users include region in the message or agent memory      |\n| \ud83d\udee1\ufe0f Restricted actions| Use memory/user ID to limit delete/copy actions              |\n| \ud83d\udcc1 Folder filtering  | Extend `ListObjects` with prefix/suffix filters              |\n| \ud83d\udce4 Upload file       | Add `PutObject` with pre-signed URL support                  |\n| \ud83e\uddfe Extra logging     | Add IP, latency, error trace to audit logs                   |\n| \ud83d\udcca Reporting         | Link Google Sheet to Looker Studio for audit dashboards      |\n| \ud83d\udea8 Security alerts   | Notify via Slack/Email when `DeleteObject` is triggered      |"
      },
      "typeVersion": 1
    },
    {
      "id": "a0f2d80c-3e15-4316-82a2-10145760e966",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        352
      ],
      "parameters": {
        "color": 5,
        "height": 112,
        "content": "### **Webhook Trigger**\nSlack, Telegram, or custom chat platform \u2192 connects to n8n."
      },
      "typeVersion": 1
    },
    {
      "id": "e099afbd-5f92-40d3-aa3e-c22e719c0574",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        256
      ],
      "parameters": {
        "color": 5,
        "height": 208,
        "content": "\n### **OpenAI Agent**\n   - Model: `gpt-4` or `gpt-3.5-turbo`\n   - Memory: Simple Memory Node\n   - Prompt: Instructs agent to always follow tool calls with an `AddAuditLog` call."
      },
      "typeVersion": 1
    },
    {
      "id": "2e6816bd-f7b4-4332-ae3f-864410083a6e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        928
      ],
      "parameters": {
        "color": 5,
        "width": 304,
        "height": 256,
        "content": "### **AWS S3 Nodes**\n   - Configure each tool with AWS credentials.\n   - Tools:\n     - `getAll: bucket`\n     - `getAll: file`\n     - `copy: file`\n     - `delete: file`\n     - `getAll: folder`\n     - `create: folder`"
      },
      "typeVersion": 1
    },
    {
      "id": "da526631-6758-4c91-be12-7d279a8e7fd0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        928
      ],
      "parameters": {
        "color": 5,
        "height": 256,
        "content": "### **Google Sheets Node**\n   - Sheet: `AWS S3 Audit Logs`\n   - Operation: `Append or Update Row`\n   - Columns (must match input keys):  \n     - `timestamp`, `tool`, `status`, `chat_prompt`, `parameters`, `user_name`, `tool_call_reasoning`"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ac313ae3-60e9-4145-8c45-72c3192a96f2",
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AWS S3 Manager Agent": {
      "main": [
        []
      ]
    },
    "Copy a file in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Delete a file in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many files in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create a folder in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many buckets in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many folders in AWS S3": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append or update row in sheet in Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AWS S3 Manager Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}