Skip to content

feat(agents-on-aws-lambda): add pattern 3 for agent in Lambda MicroVM with AgentCore Observability - #2076

Merged
rajeshkumarravi merged 5 commits into
awslabs:mainfrom
vipulg1993:feat/add-lambda-microvm-agentcore-observability-sample
Sep 14, 2026
Merged

rajeshkumarravi merged 5 commits into
awslabs:mainfrom
vipulg1993:feat/add-lambda-microvm-agentcore-observability-sample

Conversation

@vipulg1993

Copy link
Copy Markdown
Contributor

Closes #2075.

What this PR adds

A new 03-agent-in-lambda-microvm/ folder under agents-on-aws-lambda/ that hosts a Strands agent inside a Lambda MicroVM and exports OTLP telemetry (traces, spans, structured logs, token metrics) to AgentCore Observability via the ADOT Python SDK. Full motivation and design in the RFC.

File layout mirrors the two existing patterns:

03-agent-in-lambda-microvm/
├── README.md
├── deploy.py            # 9-step idempotent deploy
├── invoke.py            # launch, mint token, POST test prompts
├── cleanup.py           # idempotent teardown
├── config.py            # constants + OTEL env-var builder
├── requirements.txt     # boto3 >= 1.43.72
└── app/
    ├── Dockerfile           # al2023-minimal ARM64 + Python 3.11 + ADOT
    ├── agent.py             # Strands agent + http.server on :8080
    ├── entrypoint.sh        # opentelemetry-instrument wrapper
    └── requirements.txt     # aws-opentelemetry-distro, strands-agents[otel], boto3

Also updated

agents-on-aws-lambda/README.md adds a third row to the "Patterns at a glance" table and a matching "Pattern 3" section so the new folder is discoverable. Style matches the two existing entries.

Tested end-to-end

  • python deploy.pycreate_microvm_image reaches CREATED in ~135 s (ARM64, 2 GB baseline)
  • python invoke.py → 3 prompts through the per-VM HTTPS endpoint, HTTP 200 each
  • CloudWatch Logs Insights confirms 5 nested OTLP spans per invoke land in /aws/bedrock-agentcore/runtimes/<agent-id> with session.id, aws.lambda.microvm.image_name, and aws.lambda.microvm.image_version propagated
  • python cleanup.py tears everything down (MicroVMs, image, IAM roles, S3 bucket) idempotently

Checklist

  • Follows CONTRIBUTING.md
  • Works against the latest main
  • No confidential info / internal URLs / account IDs
  • README structure matches the two existing patterns
  • Idempotent scripts (safe to rerun)
  • python3 -m py_compile passes on every .py file
  • CreateMicrovmImage payload validates against the boto3 service model

Vipul Gargav added 3 commits September 11, 2026 14:16
…ability

Adds a third pattern under agents-on-aws-lambda that hosts a Strands
agent inside a Lambda MicroVM and exports OTLP telemetry (traces,
spans, logs, token metrics) to Amazon CloudWatch via the AWS Distro
for OpenTelemetry (ADOT) Python SDK.

Motivation
----------
- Pattern 1 (01-lambda-invokes-runtime) covers Lambda -> AgentCore runtime
- Pattern 2 (02-agent-in-lambda) covers a Strands agent wrapped in a
  Lambda function using the managed ADOT Lambda Layer
- Neither covers Lambda MicroVMs, the compute primitive Claude Managed
  Agents and Cursor Cloud Agents use today. The ADOT wiring is
  materially different: the managed Lambda Layer does not apply to
  MicroVMs, so this sample installs the ADOT SDK into the container
  image and bakes the AgentCore Observability env-var contract into
  the MicroVM snapshot at image build time.

What is added
-------------
03-integrations/agents-hosted-outside-runtime/agents-on-aws-lambda/
  03-agent-in-lambda-microvm/
    README.md           awslabs-style: Architecture, Files, Prereqs,
                        Quick Start, How observability works, Viewing
                        traces, Additional Resources
    deploy.py           9-step idempotent deploy: Transaction Search,
                        log group + resource policy, S3 bucket, IAM
                        roles, package + upload, create_microvm_image
    invoke.py           Launch a MicroVM, mint an auth token, POST
                        test prompts, print CloudWatch verify links
    cleanup.py          Idempotent teardown
    config.py           Shared constants + otel_env() builder
    requirements.txt    boto3 >= 1.43.72 (client side)
    app/
      Dockerfile        al2023-minimal ARM64 + Python 3.11 + ADOT
      agent.py          Strands + Bedrock + http.server on :8080
      entrypoint.sh     opentelemetry-instrument wrapper
      requirements.txt  aws-opentelemetry-distro>=0.18.0,
                        strands-agents[otel], boto3
      .dockerignore

Tested end-to-end
-----------------
- deploy.py -> image CREATED in ~135s (ARM64, 2 GB baseline)
- invoke.py -> 3 prompts, HTTP 200 each
- CloudWatch Logs Insights confirms 5 nested OTLP spans per invoke
  land in /aws/bedrock-agentcore/runtimes/<agent-id> with session.id,
  aws.lambda.microvm.image_name, and aws.lambda.microvm.image_version
  propagated
- cleanup.py -> tears everything down cleanly
Rebalance the README so it introduces the sample on its own terms
rather than positioning it against patterns 1 and 2.

- Replace the "Why this is not just Pattern 2 with a different host"
  section with a short "What MicroVMs bring to agent observability"
  paragraph focused on what the primitive actually offers (long-lived
  process, snapshot resume, per-VM identity attributes).
- Move the "ADOT SDK vs ADOT Collector" note up into the "How
  observability works" section as the leading subsection ("Why the
  ADOT SDK"), so the transport choice is explained as design context
  rather than a lesson learned.
- Move the operational quirks (build-role credential caching, reserved
  env vars, log-stream pre-creation, ready-hook toggle, missing spans)
  into a Troubleshooting section framed as symptom / cause / fix, so a
  reader hits them only if they encounter them.
Add the third row to the "Patterns at a glance" table and a matching
"Pattern 3 — Agent in Lambda MicroVM" section so the new pattern is
discoverable from the folder root. Style matches the existing entries.
@github-actions github-actions Bot added the 03-integrations 03-integrations label Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

Latest scan for commit: a9d99a8 | Updated: 2026-09-14 18:47:58 UTC

Security Scan Results

Vipul Gargav added 2 commits September 11, 2026 16:40
Address the 13 findings reported by `python-lint` on the initial PR:

- Remove unused `# noqa` directives (RUF100) — the ruff config for this
  repo doesn't enable BLE001, E402, or S310, so the suppressions were
  redundant.
- Sort imports in cleanup.py, deploy.py, invoke.py (I001).
- Rewrite `dict(...)` call to a dict literal in deploy.py (C408).
- Drop the extraneous `f` prefix on 4 f-strings that had no
  placeholders (F541).

All fixes are purely stylistic; runtime behaviour is unchanged. Verified
with `ruff check` (clean) and `python3 -m py_compile` (all pass).
The python-lint workflow runs two checks: `ruff check` (fixed in the
previous commit) and `ruff format --check`. Applying `ruff format` to
match the repo's formatter output — joined split f-strings that fit on
a single line, single-space around operators, and the standard two
blank lines between top-level function definitions.

No behavioural changes. Verified locally with both `ruff check` and
`ruff format --check` clean.
@rajeshkumarravi
rajeshkumarravi merged commit c01ee10 into awslabs:main Sep 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

03-integrations 03-integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: Add pattern 3 (agent in Lambda MicroVM) to agents-on-aws-lambda

2 participants