<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daniel Sim-Xien</title>
    <description>The latest articles on DEV Community by Daniel Sim-Xien (@dxsim).</description>
    <link>https://dev.to/dxsim</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3068580%2F5304cff0-1903-4240-ac5c-d274c7d49910.png</url>
      <title>DEV Community: Daniel Sim-Xien</title>
      <link>https://dev.to/dxsim</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dxsim"/>
    <language>en</language>
    <item>
      <title>Docker-Compose Gettings IAM Error Credentials</title>
      <dc:creator>Daniel Sim-Xien</dc:creator>
      <pubDate>Fri, 12 Dec 2025 15:32:15 +0000</pubDate>
      <link>https://dev.to/dxsim/docker-compose-gettings-iam-error-credentials-42d</link>
      <guid>https://dev.to/dxsim/docker-compose-gettings-iam-error-credentials-42d</guid>
      <description>&lt;p&gt;Let's say you've successfully written your first docker-compose applications on your EC2 of your choice and voila deployed it! After maybe a few hours you might get errors like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F00gyfdo6ph3ytj805rs3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F00gyfdo6ph3ytj805rs3.png" alt=" " width="800" height="60"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9iow98kc6o4s5yefrwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9iow98kc6o4s5yefrwb.png" alt=" " width="800" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above was a streamlit project state that got deployed with docker-compose, but IAM credentials might happen regardless of your deployment configuration.&lt;/p&gt;
&lt;h1&gt;
  
  
  So what happened?
&lt;/h1&gt;

&lt;p&gt;To understand this, we need a basic understanding of EC2 Instance Metadata.&lt;/p&gt;

&lt;p&gt;EC2 instance metadata is a REST API accessible only from within the EC2 instance at a fixed link-local IP address: &lt;a href="http://169.254.169.254/latest/meta-data/" rel="noopener noreferrer"&gt;http://169.254.169.254/latest/meta-data/&lt;/a&gt;. It requires no authentication and provides information in plaintext or JSON format.&lt;/p&gt;

&lt;p&gt;You can test this endpoint using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \
&amp;amp;&amp;amp; curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  So why is our Docker-Compose project failing then?
&lt;/h1&gt;

&lt;p&gt;Put simply, its because usually we isolate the docker-compose projects into its own network bridge, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  api:
    build:
      context: .
      dockerfile: Dockerfile.api
    expose:
      - "8000"
    volumes:
      - ./tools:/app/tools
    environment:
      - PYTHONUNBUFFERED=1
    restart: unless-stopped
    networks:
      - app-network

  streamlit:
    build:
      context: .
      dockerfile: Dockerfile.streamlit
    ports:
      - "8501:8501"
    expose:
      - "8501"
    environment:
      - PYTHONUNBUFFERED=1
    depends_on:
      - api
    restart: unless-stopped
    networks:
      - app-network

networks:
  app-network:
    driver: bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When creating networks like above, accessing this metadata becomes challenging when applications run inside Docker containers, due to Docker’s network isolation and default networking configurations.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do we solve it
&lt;/h1&gt;

&lt;p&gt;The simplest way to grant a container access to EC2 metadata is to use Docker’s host network mode, which makes the container share the host’s network stack.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  api:
    build:
      context: .
      dockerfile: Dockerfile.api
    volumes:
      - ./tools:/app/tools
    environment:
      - PYTHONUNBUFFERED=1
    restart: unless-stopped
    network_mode: host

  streamlit:
    build:
      context: .
      dockerfile: Dockerfile.streamlit
    environment:
      - PYTHONUNBUFFERED=1
      - API_SERVER_URL=http://api:8000
    depends_on:
      - api
    restart: unless-stopped
    network_mode: host
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By sharing the network hosts port directly, this eliminates network isolation, allowing the container to directly access 169.254.169.254. Thus, we shouldn't have any issues regarding IAM service role credentials refreshing and EC2 instance metadata.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ec2</category>
      <category>iam</category>
      <category>docker</category>
    </item>
    <item>
      <title>Deploying MCP Servers on AWS.. Serverlessly</title>
      <dc:creator>Daniel Sim-Xien</dc:creator>
      <pubDate>Sun, 25 May 2025 01:05:24 +0000</pubDate>
      <link>https://dev.to/dxsim/deploying-mcp-servers-on-aws-serverlessly-3eb8</link>
      <guid>https://dev.to/dxsim/deploying-mcp-servers-on-aws-serverlessly-3eb8</guid>
      <description>&lt;p&gt;At this point, you may find many if not an overwhelming amount of options when considering to deploy MCP (Model Context Protocol) servers. You can choose the embedded route where you directly create these servers through the base framework (ie &lt;a href="https://github.com/jlowin/fastmcp" rel="noopener noreferrer"&gt;FastMCP&lt;/a&gt; for Pythonistas) or relegate the creation to higher order modules (ie &lt;a href="https://github.com/evalstate/fast-agent" rel="noopener noreferrer"&gt;FastAgent&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Well today, its not so much on the creation of these servers but rather the deployment. I will zoom out and instead look at the existing architectural options on the deployment of MCP server architectures on AWS.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. AWS Solutions Library Version
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Page: &lt;a href="https://aws.amazon.com/solutions/guidance/deploying-model-context-protocol-servers-on-aws/" rel="noopener noreferrer"&gt;https://aws.amazon.com/solutions/guidance/deploying-model-context-protocol-servers-on-aws/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/aws-solutions-library-samples/guidance-for-deploying-model-context-protocol-servers-on-aws" rel="noopener noreferrer"&gt;https://github.com/aws-solutions-library-samples/guidance-for-deploying-model-context-protocol-servers-on-aws&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxjzpf3x6i2l1pkqlr2x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxjzpf3x6i2l1pkqlr2x.png" alt="Image description" width="800" height="487"&gt;&lt;/a&gt;&lt;br&gt;
This architecture shows how to securely deploy Model Context Protocol (MCP) servers on AWS using containers. It covers implementing OAuth 2.0 authentication, adding security layers like CDNs and firewalls, managing client sessions and tokens, setting up centralized logging, and ensuring high availability through container orchestration. Following this deployment helps organizations create a really well-thought out end-to-end archtecture. &lt;/p&gt;

&lt;p&gt;Would recommend deploying this if you seek secure, scalable MCP server deployment with maximum system reliability but aren't constrained by cost factors. The caveat to this solution is to a non-enterprise account holder, this may seem overengineered, especially when the mcp-server is hosted on Fargate runtimes. The other solutions listed here use AWS Lambda to host their MCP servers.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Direct AWS Lambda Deployment using FastMCP
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Page: &lt;a href="https://deepwiki.com/aws-samples/sample-serverless-mcp-servers/2.2-stateless-mcp-on-lambda-(python)" rel="noopener noreferrer"&gt;https://deepwiki.com/aws-samples/sample-serverless-mcp-servers/2.2-stateless-mcp-on-lambda-(python)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/aws-samples/sample-serverless-mcp-servers/tree/7cf498235fab11b897c553c60000be2a310ca33e/stateless-mcp-on-lambda-python" rel="noopener noreferrer"&gt;https://github.com/aws-samples/sample-serverless-mcp-servers/tree/7cf498235fab11b897c553c60000be2a310ca33e/stateless-mcp-on-lambda-python&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02hgs3s6h7l9dpsdruos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02hgs3s6h7l9dpsdruos.png" alt="Image description" width="378" height="652"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This deployment method is a serverless FastMCP server using Python on AWS Lambda. It uses AWS API Gateway for handling requests and AWS SAM for easy deployment, offering a simple way to host MCP services without managing servers. This deployment method is arguably probably the most popular for deploying mcp servers directly for python developers. It leverages FastMCP base framework so all the FastMCP functionalities are available to you from the get-go.&lt;/p&gt;

&lt;p&gt;The major caveat about using FastMCP on Lambda, you are likely to experience major cold start issues when starting your functions, approximately 3-5 seconds. Another caveat is that using python, you would have to deploy the solution with an additional LambdaAdapterLayer which is written in Rust&lt;br&gt;
&lt;code&gt;arn:aws:lambda:us-east-1:753240598075:layer:LambdaAdapterLayerX86:25&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This may be a concern if you care about making your solution as lean as possible.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Lambda-MCP-Server
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Video: &lt;a href="https://www.youtube.com/watch?v=Ejua5LQTqek&amp;amp;list=PLeAh2CQypN9V8E-pkG6ZAXj-w3dgy1qQn&amp;amp;index=2" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=Ejua5LQTqek&amp;amp;list=PLeAh2CQypN9V8E-pkG6ZAXj-w3dgy1qQn&amp;amp;index=2&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/mikegc-aws/Lambda-MCP-Server/tree/main?tab=readme-ov-file" rel="noopener noreferrer"&gt;https://github.com/mikegc-aws/Lambda-MCP-Server/tree/main?tab=readme-ov-file&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This wonderful gem of a library was made by Mike Chambers, a Developer Advocate at AWS. And its so far the most recent and leanest example on MCP server side implementation I've seen so far. The library takes the entire MCP protocol logic and rewrote it for faster and more efficient usage in lambda.&lt;/p&gt;

&lt;p&gt;One key boon on using this library is that the connection itself has been rewritten to be MCP-compliant while removing most of the latency issue that the previous lambda+FastMCP has. The con here is that the library is not maintained by the official FastMCP team, so you may not find long-term or most up-top-date updates on the MCP protocol using this library. Lastly, so far the library has been geared towards tool usage, instead of other things like resource, so keep that in mind.&lt;/p&gt;

&lt;p&gt;Hope you've learnt something. Feel free to Connect with me on (linkedin)[&lt;a href="https://www.linkedin.com/in/daniel-sim-xien-709445112/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/daniel-sim-xien-709445112/&lt;/a&gt;].&lt;/p&gt;

</description>
      <category>aws</category>
      <category>mcp</category>
      <category>architecture</category>
      <category>awslearner</category>
    </item>
    <item>
      <title>Crafting Minimal Viable IAM Permissions for Amazon Bedrock</title>
      <dc:creator>Daniel Sim-Xien</dc:creator>
      <pubDate>Sun, 11 May 2025 01:51:13 +0000</pubDate>
      <link>https://dev.to/dxsim/crafting-minimal-viable-iam-permissions-for-amazon-bedrock-1b5c</link>
      <guid>https://dev.to/dxsim/crafting-minimal-viable-iam-permissions-for-amazon-bedrock-1b5c</guid>
      <description>&lt;p&gt;In many ways, most AWS accounts usually require very specific minimum viable permissions (MVP) assigned to user groups. This is usually controlled through templates like AWS Organizations Landing Zone, where the account governor usually has to manually define the scope of access manually. What if we could generate permissions policies via a prompt?&lt;/p&gt;

&lt;h1&gt;
  
  
  Minimal Viable IAM Permissions for Amazon Bedrock with Langchain
&lt;/h1&gt;

&lt;p&gt;As Cloud Governance specialist, we now have access to powerful tools like Amazon Bedrock and Langchain. But with great power comes great responsibility, especially when it comes to security. In this post, we'll explore how to create minimal viable IAM (Identity and Access Management) permissions for Amazon Bedrock when using it with Langchain, and we'll include some Python code examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Amazon Bedrock&lt;/strong&gt;: A fully managed service offering high-performing foundation models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Langchain&lt;/strong&gt;: A framework for developing applications powered by language models.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM&lt;/strong&gt;: AWS's Identity and Access Management service for controlling access to AWS resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Importance of Minimal Permissions
&lt;/h2&gt;

&lt;p&gt;Implementing the principle of least privilege is crucial when working with AI services. It helps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reduce the potential attack surface&lt;/li&gt;
&lt;li&gt;Minimize the risk of unintended actions&lt;/li&gt;
&lt;li&gt;Comply with security best practices&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Key Bedrock Actions for Langchain Integration
&lt;/h2&gt;

&lt;p&gt;When using Langchain with Bedrock, we typically need these main actions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;bedrock:InvokeModel&lt;/code&gt;: To call the model&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bedrock:ListFoundationModels&lt;/code&gt;: To list available models (optional)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bedrock:GetFoundationModel&lt;/code&gt;: To get model details (optional)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Sample IAM Policy
&lt;/h2&gt;

&lt;p&gt;Here's a minimal IAM policy for Bedrock use with Langchain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"bedrock:InvokeModel"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-v2"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This policy allows invoking the Claude v2 model, which is commonly used with Langchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python Code Example
&lt;/h2&gt;

&lt;p&gt;Let's see how to use this with Langchain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langchain.llms&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Bedrock&lt;/span&gt;

&lt;span class="c1"&gt;# Assume AWS credentials are set up in your environment
&lt;/span&gt;&lt;span class="n"&gt;bedrock_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;service_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;bedrock-runtime&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;region_name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;us-west-2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize the Bedrock LLM
&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Bedrock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;anthropic.claude-v2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;bedrock_client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;model_kwargs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max_tokens_to_sample&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Use the LLM
&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Produce a IAM permissions policy with only read and write access to the bucket name &amp;lt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;INSERT BUCKET NAME HERE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;gt; only&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example we're using the boto3 client with Langchain's Bedrock integration. The IAM permissions we set earlier allow this code to run successfully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use IAM roles&lt;/strong&gt;: Attach these permissions to IAM roles rather than individual users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regular audits&lt;/strong&gt;: Periodically review and update your IAM policies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment-specific permissions&lt;/strong&gt;: Use different permissions for development, testing, and production environments.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;If you encounter permission issues, check the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ensure the IAM policy is attached correctly to your role or user.&lt;/li&gt;
&lt;li&gt;Verify that the region in your code matches the region in the IAM policy.&lt;/li&gt;
&lt;li&gt;Check AWS CloudTrail logs for specific permission denied errors.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By implementing minimal viable IAM permissions for Amazon Bedrock when using Langchain, you're taking a crucial step in securing your AI applications. Of course you gotta remember to regularly review and update your permissions as your application's needs evolve.&lt;/p&gt;

&lt;p&gt;Happy secure coding!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>ai</category>
      <category>langchain</category>
      <category>bedrock</category>
    </item>
  </channel>
</rss>
