Stop Paying for OpenAI: Build a Private AI Agent with n8n & AWS Bedrock

In this guide, I’m going to show you how to build a fully private AI Agent using n8n and AWS Bedrock. We will leverage the state-of-the-art Claude 3.5 Sonnet model directly inside your own AWS account. This approach is more secure, gives you granular control over permissions, and keeps your data within your existing cloud infrastructure.

Whether you are automating a SaaS like I am with Banglasend, or just want to learn how to build enterprise-grade AI tools, this tutorial is for you. Let’s dive in.

Why I Stopped Using OpenAI for My AI Agents

Everyone is building AI agents right now. But almost every tutorial you watch has the same catch: “Paste your OpenAI API Key here.”

For hobbyists, that’s fine. But as a DevOps engineer and SaaS founder, I see two massive problems with this:

  1. Privacy: sending sensitive customer data (like support emails) to a public API endpoint isn’t always acceptable for enterprise clients.
  2. Cost: OpenAI’s API bills can stack up fast.

Today, I’m going to show you a better way. We are going to build a fully private AI Agent using n8n and AWS Bedrock. We will leverage the state-of-the-art Claude 3.5 Sonnet model directly inside your AWS account—securely, cheaply, and with zero third-party API keys.

The Architecture

We are building a “Support Triage Agent” for my SaaS, Banglasend.

  • Trigger: An email arrives (or a Webhook from a contact form).
  • The Brain: n8n sends the text to AWS Bedrock (running Claude 3.5 Sonnet).
  • The Action: The AI categorizes the issue, drafts a reply, and updates our database.

Step 1: Prerequisites

Before opening n8n, we need to do some work in the AWS Console.

1. Request Model Access. Go to AWS Bedrock > Model access.

  • Click “Modify model access.
  • Check the box for Claude 3.5 Sonnet (under Anthropic).
  • Note: If you are in us-east-1, ensure you request the “US Anthropic Claude 3.5 Sonnet” profile.

2. Create an IAM User. Create a new IAM user (e.g., n8n-bedrock-user) and attach the following policy. Pro Tip: Don’t just use AdminAccess!

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "BedrockAccess",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:ListFoundationModels"
            ],
            "Resource": "*"
        }
    ]
}

Generate an Access Key and Secret Key for this user. Save them.

Step 2: Connect n8n to AWS Bedrock

Open your n8n workflow editor.

  1. Add a new node and search for AWS Bedrock.
  2. Select “Chat” as the operation.
  3. Credentials: Create a new credential and paste the AWS Key and Secret you just generated.
  4. Region: Set this to the region where you requested the model (usually us-east-1 or us-west-2).

Step 3: The “Inference Profile” Gotcha (Important!)

This is where most people get stuck. If you select the standard anthropic.claude-3-5-sonnet... model ID, you might get an error saying “On-demand throughput isn’t supported.”

The Fix: For the newest models, AWS requires you to use the Inference Profile ID.

  • In the n8n Bedrock node, under Model, select “Expression” (the little gears icon).
  • Paste this ID for US regions: us.anthropic.claude-3-5-sonnet-20241022-v2:0

Step 4: The System Prompt

The magic of an AI agent is in the System Prompt. This tells the AI who it is. Here is the exact prompt I use for Banglasend:

System Prompt:

You are 'BanglaBot', the Tier-1 Support Agent for Banglasend (a remittance SaaS platform).

Your Goal: Read the user's inquiry and classify it into one of three categories:
1. "Transaction Issue" (Money not received, delayed)
2. "Account Issue" (Login failed, KYC pending)
3. "General Inquiry" (Pricing, how-to)

Instructions:
- Be polite, professional, and empathetic.
- If the user is angry, acknowledge their frustration.
- Do NOT make up transaction statuses. If you don't know, ask them for a Transaction ID.
- Keep the reply under 100 words.

Output your response in JSON format:
{
  "category": "...",
  "draft_reply": "..."
}

Step 5: Testing the Agent

Connect a Manual Trigger to your Bedrock node and run it. You should see a perfectly formatted JSON output with a polite support email draft.

From here, you can connect this to a Gmail node to send the draft to yourself, or a Slack node to alert your team.

Conclusion

You now have a private, secure AI agent running on your own infrastructure. No monthly subscriptions to OpenAI, and full control over your data privacy.

If you want to see how to scale this setup using Kubernetes (EKS) for high-volume workflows, check out my YouTube channel, where I deep dive into the DevOps side of n8n.

Conclusion

And there you have it—a fully functional, intelligent AI agent running entirely on your own infrastructure. By combining the visual workflow power of n8n with the secure, enterprise-grade models in AWS Bedrock, you’ve built a solution that is ready for the real world.

You are no longer just “using AI”; you are engineering it. You’ve removed the dependency on third-party API keys, kept your customer data secure within your AWS perimeter, and set yourself up with a scalable architecture.

Where to go from here? This setup is perfect for handling hundreds of requests. But what happens when you need to handle thousands? That’s where Kubernetes comes in. In my next few posts (and on my YouTube channel), I’ll be showing you how to take this n8n setup and scale it horizontally on AWS EKS to handle massive production workloads.

Next Steps:

  • Download the Workflow JSON to import this agent directly into your n8n instance.
  • Check out my YouTube Channel for the video walkthrough of this tutorial.
  • Leave a comment below if you ran into any permission issues with IAM—I’m happy to help troubleshoot.

Happy automating!

Here is the JSON workflow file corresponding to the tutorial. You can save this code block as a .json file (e.g., n8n_bedrock_agent.json) and import it directly into n8n.

How to Import:

  1. Copy the code below.
  2. Open your n8n Editor.
  3. Press Ctrl + V (or Cmd + V) to paste it directly onto the canvas, OR go to the top right menu > Import from File.
  4. Important: You must open the “AWS Bedrock” node and select your own credentials (as created in the tutorial).
{
  "name": "AWS Bedrock AI Agent - Support Triage",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger-node-id",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        460,
        340
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
          "mode": "id"
        },
        "prompt": "={{ $json.body.message || \"I haven't received my money yet. It's been 2 days.\" }}",
        "systemPrompt": "You are 'BanglaBot', the Tier-1 Support Agent for Banglasend (a remittance SaaS platform).\n\nYour Goal: Read the user's inquiry and classify it into one of three categories:\n1. \"Transaction Issue\" (Money not received, delayed)\n2. \"Account Issue\" (Login failed, KYC pending)\n3. \"General Inquiry\" (Pricing, how-to)\n\nInstructions:\n- Be polite, professional, and empathetic.\n- If the user is angry, acknowledge their frustration.\n- Do NOT make up transaction statuses. If you don't know, ask them for a Transaction ID.\n- Keep the reply under 100 words.\n\nOutput your response in JSON format:\n{\n  \"category\": \"...\",\n  \"draft_reply\": \"...\"\n}"
      },
      "id": "bedrock-node-id",
      "name": "AWS Bedrock (Claude 3.5)",
      "type": "n8n-nodes-base.awsBedrock",
      "typeVersion": 1,
      "position": [
        680,
        340
      ],
      "credentials": {
        "aws": {
          "id": "YOUR_CREDENTIAL_ID_HERE",
          "name": "AWS account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Agent Response\n**Category:** {{ JSON.parse($json.response).category }}\n\n**Draft Reply:**\n> {{ JSON.parse($json.response).draft_reply }}"
      },
      "id": "markdown-output",
      "name": "Format Output",
      "type": "n8n-nodes-base.markdown",
      "typeVersion": 1,
      "position": [
        900,
        340
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking \"Execute Workflow\"": {
      "main": [
        [
          {
            "node": "AWS Bedrock (Claude 3.5)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AWS Bedrock (Claude 3.5)": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

What this workflow does:

  1. Manual Trigger: Simulates an incoming message (I added a default test message: “I haven’t received my money yet…”).
  2. AWS Bedrock: Uses the us.anthropic.claude-3-5-sonnet model ID with your “BanglaBot” system prompt.
  3. Format Output: Parses the JSON response from the AI and displays it cleanly in the n8n UI so you can verify it worked.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply