I Tried Mounting Amazon S3 Files from Agents Outside a VPC (AgentCore Runtime and Lambda MicroVMs)

I Tried Mounting Amazon S3 Files from Agents Outside a VPC (AgentCore Runtime and Lambda MicroVMs)

Using the S3 Files Endpoints added in this update, AgentCore Runtime and Lambda MicroVMs without a VPC connection mounted S3 Files in the Tokyo region and could read and write. Written files were also visible in S3.
2026.11.30

This page has been translated by machine translation. View original

Introduction

On November 29, 2026, an update made it possible for AgentCore Runtime and Lambda MicroVMs running outside a VPC to mount Amazon S3 Files file systems.

https://aws.amazon.com/jp/about-aws/whats-new/2026/11/amazon-s3-files-mount-agents-outside-vpc/

This article describes the results of creating AgentCore Runtime and Lambda MicroVMs without attaching them to a VPC, and confirming that they can mount an Amazon S3 Files file system and read from and write to it.

Verification Environment

  • Region: Tokyo (ap-northeast-1)
  • aws-cli: 2.42.6
  • AgentCore Runtime: PYTHON_3_13 (code deployed from a zip in S3)
  • Lambda MicroVMs base image: al2023-1 (version 4.2), ARM_64
  • amazon-efs-utils: 4.0.0 (an RPM built from source and added to the Lambda MicroVMs image)

IAM Permissions for Connecting from Outside a VPC

In addition to the route that connects to mount targets in a VPC, S3 Files gained a new route in this update: S3 Files Endpoints, which connect from outside a VPC.

Using Endpoints requires the following IAM permissions.

  • s3files:CreateMountSession
  • For the client operations you use (ClientMount and ClientWrite in this case), both the s3files: and s3files-endpoint: actions

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files-networking-endpoint-permissions.html

This time, I attached the following policy to both the AgentCore Runtime role and the MicroVM execution role.

The attached policy and how to attach it (compute-s3files-policy.json)

The s3files:GetAccessPoint in the third Statement is required to validate the access point when creating the AgentCore Runtime.

compute-s3files-policy.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "MountSession",
      "Effect": "Allow",
      "Action": ["s3files:CreateMountSession"],
      "Resource": "arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0"
    },
    {
      "Sid": "MountAndWriteViaVpcAndEndpoint",
      "Effect": "Allow",
      "Action": [
        "s3files:ClientMount",
        "s3files:ClientWrite",
        "s3files-endpoint:ClientMount",
        "s3files-endpoint:ClientWrite"
      ],
      "Resource": "arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0",
      "Condition": {
        "StringEquals": {
          "s3files:AccessPointArn": "arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0"
        }
      }
    },
    {
      "Sid": "ValidateAccessPoint",
      "Effect": "Allow",
      "Action": ["s3files:GetAccessPoint"],
      "Resource": [
        "arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0",
        "arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0"
      ]
    }
  ]
}

Save the policy above as compute-s3files-policy.json and attach it to each role.

aws iam put-role-policy \
  --role-name <ロール名> \
  --policy-name s3files-mount \
  --policy-document file://compute-s3files-policy.json

S3 Files File System and Access Point

I created a file system from a bucket, and also created an access point.

aws s3files create-file-system \
  --bucket arn:aws:s3:::amzn-s3-demo-bucket \
  --prefix agent-data/ \
  --role-arn arn:aws:iam::111122223333:role/s3f-outvpc-fs-role

aws s3files create-access-point \
  --file-system-id fs-0123456789abcdef0 \
  --posix-user uid=1000,gid=1000 \
  --root-directory 'path=/agent,creationPermissions={ownerUid=1000,ownerGid=1000,permissions=755}'

The file system prefix is agent-data/, and the access point root is /agent. Therefore, files placed in the mount destination are stored in S3 under the key agent-data/agent/.

Reading and Writing from AgentCore Runtime

Creating the Runtime

I created it with networkMode set to PUBLIC, passing the access point and mount path to --filesystem-configurations.

aws bedrock-agentcore-control create-agent-runtime \
  --agent-runtime-name s3f_outvpc_agent \
  --agent-runtime-artifact '{"codeConfiguration":{"code":{"s3":{"bucket":"amzn-s3-demo-bucket","prefix":"code/agent.zip"}},"runtime":"PYTHON_3_13","entryPoint":["main.py"]}}' \
  --role-arn arn:aws:iam::111122223333:role/s3f-outvpc-agent-role \
  --network-configuration '{"networkMode":"PUBLIC"}' \
  --filesystem-configurations '[{"s3FilesAccessPoint":{"accessPointArn":"arn:aws:s3files:ap-northeast-1:111122223333:file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0","mountPath":"/mnt/s3data"}}]'

The AgentCore documentation states that networkMode must be VPC for S3 Files and EFS. This time, I was able to create the Runtime with networkMode left as PUBLIC.

https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-filesystem-configurations.html

Agent code (main.py)
import json, os
from http.server import BaseHTTPRequestHandler, HTTPServer

MOUNT = "/mnt/s3data"

def handle(body):
    action = body.get("action", "info")
    out = {"action": action}
    if action == "write":
        path = os.path.join(MOUNT, body["name"])
        with open(path, "w") as f:
            f.write(body["content"])
        out["wrote"] = path
    elif action == "read":
        with open(os.path.join(MOUNT, body["name"])) as f:
            out["content"] = f.read()
    elif action == "ls":
        out["files"] = sorted(os.listdir(MOUNT))
    out["mount_lines"] = [l.strip() for l in open("/proc/mounts") if MOUNT in l]
    out["files"] = out.get("files") or (sorted(os.listdir(MOUNT)) if os.path.isdir(MOUNT) else None)
    return out

class H(BaseHTTPRequestHandler):
    def _send(self, code, obj):
        data = json.dumps(obj).encode()
        self.send_response(code)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(data)))
        self.end_headers()
        self.wfile.write(data)

    def do_GET(self):
        self._send(200, {"status": "Healthy"})

    def do_POST(self):
        n = int(self.headers.get("Content-Length", 0))
        try:
            body = json.loads(self.rfile.read(n) or b"{}")
            self._send(200, handle(body))
        except Exception as e:
            self._send(200, {"error": repr(e)})

HTTPServer(("0.0.0.0", 8080), H).serve_forever()

Writing and Reading from a Different Session

I wrote a file in the first session, then read the same file in a second session with a different session ID.

aws bedrock-agentcore invoke-agent-runtime \
  --agent-runtime-arn arn:aws:bedrock-agentcore:ap-northeast-1:111122223333:runtime/s3f_outvpc_agent-xxxxxxxxxx \
  --runtime-session-id session-s3f-outvpc-verify-0001-aaaaaaaaaa \
  --content-type application/json \
  --cli-binary-format raw-in-base64-out \
  --payload '{"action":"write","name":"hello-from-agentcore.txt","content":"written from AgentCore Runtime (PUBLIC)"}' \
  out-write.json

aws bedrock-agentcore invoke-agent-runtime \
  --agent-runtime-arn arn:aws:bedrock-agentcore:ap-northeast-1:111122223333:runtime/s3f_outvpc_agent-xxxxxxxxxx \
  --runtime-session-id session-s3f-outvpc-verify-0002-bbbbbbbbbb \
  --content-type application/json \
  --cli-binary-format raw-in-base64-out \
  --payload '{"action":"read","name":"hello-from-agentcore.txt"}' \
  out-read.json

In the first response, wrote returned /mnt/s3data/hello-from-agentcore.txt, so the write succeeded. In the second response, content returned written from AgentCore Runtime (PUBLIC), so the content written in the first session could be read from a different session.

Reading and Writing from Lambda MicroVMs

Creating the Image

There is no setting for specifying a file system when launching Lambda MicroVMs. The application inside the image runs the mount command, so I install the mount helper amazon-efs-utils (version 4.0.0 or later) in the image.

At the time of writing, the latest version in the efs-utils RPM repository was 3.4.0, so I built an RPM package from the source on GitHub and bundled it into the image.

https://github.com/aws/efs-utils/releases/tag/v4.0.0

RPM build script for efs-utils 4.0.0 (build-rpm.sh)

Run it inside an Amazon Linux 2023 (arm64) container; the RPM is output to /out. The MicroVM image is ARM_64, so I use the aarch64 RPM.

#!/bin/bash
# Build amazon-efs-utils v4.0.0 RPM for Amazon Linux 2023 (arm64) inside a container.
set -ex
dnf install -y --allowerasing git make gcc gcc-c++ cmake perl golang rpm-build curl tar gzip which openssl-devel
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
git clone --depth 1 --branch v4.0.0 https://github.com/aws/efs-utils /build/efs-utils
cd /build/efs-utils
make rpm-without-system-rust
cp build/*.rpm /out/
ls -l /out

The Dockerfile is as follows. It copies and installs the built RPM, then starts app.py.

FROM public.ecr.aws/lambda/microvms:al2023-minimal
COPY amazon-efs-utils-4.0.0-1.amzn2023.aarch64.rpm /tmp/
RUN dnf install -y python3 python3-pip util-linux nfs-utils openssl stunnel which \
 && pip3 install botocore \
 && rpm -ivh --nodeps /tmp/amazon-efs-utils-4.0.0-1.amzn2023.aarch64.rpm \
 && rpm -q amazon-efs-utils \
 && dnf clean all && rm -f /tmp/*.rpm
WORKDIR /app
COPY app.py .
EXPOSE 8080
CMD ["python3", "app.py"]
Application code (app.py)
import json, os, subprocess
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

MOUNT = "/mnt/s3data"
FS_ID = os.environ.get('S3FILES_FS_ID', 'fs-0123456789abcdef0')
AP_ID = os.environ.get('S3FILES_AP_ID', 'fsap-0123456789abcdef0')

def sh(cmd):
    p = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=90)
    return {"cmd": cmd, "rc": p.returncode, "out": p.stdout[-3000:], "err": p.stderr[-3000:]}

def handle(b):
    a = b.get("action", "info")
    out = {"action": a}
    if a == "mount":
        os.makedirs(MOUNT, exist_ok=True)
        out["mount"] = sh(f"mount -t s3files -o accesspoint={AP_ID} {FS_ID} {MOUNT}")
        if out["mount"]["rc"] != 0:
            out["efs_log"] = sh("tail -n 40 /var/log/amazon/efs/*.log")
    elif a == "write":
        p = os.path.join(MOUNT, b["name"]); open(p, "w").write(b["content"]); out["wrote"] = p
    elif a == "read":
        out["content"] = open(os.path.join(MOUNT, b["name"])).read()
    elif a == "sh":
        out["sh"] = sh(b["cmd"])
    out["mount_lines"] = [l.strip() for l in open("/proc/mounts") if MOUNT in l]
    out["files"] = sorted(os.listdir(MOUNT)) if os.path.isdir(MOUNT) else None
    return out

class H(BaseHTTPRequestHandler):
    def _send(self, obj):
        d = json.dumps(obj).encode()
        self.send_response(200); self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(d))); self.end_headers(); self.wfile.write(d)
    def do_GET(self): self._send({"status": "ok"})
    def do_POST(self):
        n = int(self.headers.get("Content-Length", 0))
        try: self._send(handle(json.loads(self.rfile.read(n) or b"{}")))
        except Exception as e: self._send({"error": repr(e)})

ThreadingHTTPServer(("0.0.0.0", 8080), H).serve_forever()

I placed a zip containing the Dockerfile, app.py, and the RPM in S3 and created the image. The specified settings are as follows.

  • --code-artifact: the zip placed in S3
  • --base-image-arn: the MicroVM base image al2023-1
  • --build-role-arn: the role for building the image
  • --additional-os-capabilities: ["ALL"]

https://docs.aws.amazon.com/lambda/latest/dg/microvms-images.html

aws lambda-microvms create-microvm-image \
  --name s3f-outvpc-image \
  --code-artifact uri=s3://amzn-s3-demo-bucket/code/app.zip \
  --base-image-arn arn:aws:lambda:ap-northeast-1:aws:microvm-image:al2023-1 \
  --build-role-arn arn:aws:iam::111122223333:role/s3f-outvpc-microvm-build-role \
  --additional-os-capabilities '["ALL"]'

After confirming with get-microvm-image that the state was CREATED, I launched the MicroVM.

Launching and Mounting

I did not use a VPC network connector; I launched it by specifying the AWS-managed network connectors (HTTP_INGRESS and INTERNET_EGRESS).

aws lambda-microvms run-microvm \
  --image-identifier arn:aws:lambda:ap-northeast-1:111122223333:microvm-image:s3f-outvpc-image \
  --ingress-network-connectors arn:aws:lambda:ap-northeast-1:aws:network-connector:aws-network-connector:HTTP_INGRESS \
  --egress-network-connectors arn:aws:lambda:ap-northeast-1:aws:network-connector:aws-network-connector:INTERNET_EGRESS \
  --execution-role-arn arn:aws:iam::111122223333:role/s3f-outvpc-microvm-role \
  --maximum-duration-in-seconds 3600

Once the state became RUNNING in get-microvm, I issued an authentication token and used curl to instruct the application to mount.

aws lambda-microvms create-microvm-auth-token \
  --microvm-identifier <microvm-id> \
  --expiration-in-minutes 60 \
  --allowed-ports '[{"port":8080}]'

curl -X POST https://<microvm-endpoint>/ \
  -H 'X-aws-proxy-auth: <TOKEN>' \
  -H 'X-aws-proxy-port: 8080' \
  -d '{"action":"mount"}'

The response was as follows.

{"action": "mount", "mount": {"cmd": "mount -t s3files -o accesspoint=fsap-0123456789abcdef0 fs-0123456789abcdef0 /mnt/s3data", "rc": 0, "out": "", "err": "Could not start amazon-efs-mount-watchdog, unrecognized init system \"python3\"\n"}, "mount_lines": ["127.0.0.1:/ /mnt/s3data nfs4 rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,noresvport,proto=tcp,port=20192,timeo=600,retrans=2,sec=sys,clientaddr=127.0.0.1,local_lock=none,addr=127.0.0.1 0 0"], "files": ["hello-from-agentcore.txt"]}

I read the mount log (/var/log/amazon/efs/mount.log) by running cat through the sh action of app.py (which executes the received command inside the MicroVM). The relevant lines from the successful mount are as follows.

2026-11-30 03:09:19 UTC - INFO - Failed to resolve apne1-az4.fs-0123456789abcdef0.s3files.ap-northeast-1.on.aws
2026-11-30 03:09:19 UTC - INFO - Using endpoint mode to mount filesystem fs-0123456789abcdef0
2026-11-30 03:09:23 UTC - INFO - Successfully mounted apne1-az4.fs-0123456789abcdef0.s3files.ap-northeast-1.on.aws at /mnt/s3data

When there is no reachable mount target, the mount helper connects to S3 Files Endpoints on port 443.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files-networking.html

In this log, hostname resolution failed and Endpoints mode was selected.

Writing Another File and Reading the File Written from AgentCore Runtime

From the MicroVM, I wrote another file and read hello-from-agentcore.txt, which had been written from AgentCore Runtime.

curl -X POST https://<microvm-endpoint>/ \
  -H 'X-aws-proxy-auth: <TOKEN>' \
  -H 'X-aws-proxy-port: 8080' \
  -d '{"action":"write","name":"hello-from-microvm.txt","content":"written from Lambda MicroVM (no VPC)"}'

curl -X POST https://<microvm-endpoint>/ \
  -H 'X-aws-proxy-auth: <TOKEN>' \
  -H 'X-aws-proxy-port: 8080' \
  -d '{"action":"read","name":"hello-from-agentcore.txt"}'

When I read hello-from-agentcore.txt from the MicroVM, it returned the content written from AgentCore Runtime, written from AgentCore Runtime (PUBLIC).

Reflection on the S3 Side

According to the documentation, an updated file is exported to S3 after writes to that file have paused for 60 seconds.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-files-synchronization.html

When I ran aws s3 ls about 30 seconds after writing from AgentCore Runtime, the file was not yet visible on the S3 side. When I ran aws s3 ls about 80 seconds later, it was visible. The object's LastModified was 65 seconds after the write.

The hello-from-microvm.txt written from the MicroVM also appeared in S3. The content retrieved with aws s3 cp matched what I had written, written from Lambda MicroVM (no VPC).

Summary

I confirmed that agents outside a VPC can handle S3 data as files through S3 Files Endpoints.

If you have been configuring VPC access for AgentCore Runtime or Lambda MicroVMs in order to use S3 Files with workloads that do not natively support S3, give the S3 Files Endpoints added in this update a try.

Share this article

AWSのお困り事はクラスメソッドへ