Generated banner for Diff Scanning With AWS Security Agent
Generated logo for Diff Scanning With AWS Security Agent

Diff Scanning With AWS Security Agent

AWSOfficialPublished by AWS

  • Skill
  • Workflow
  • Security
  • Apache-2.0
  • No issues found

From the author

Run a fast AWS Security Agent diff scan on only the changed code since a git ref. Use when the user asks to scan changes, run a diff scan, check what changed for security issues, scan before committing, scan before PR, or any pre-commit/pre-push security check.
— the description by AWS

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This workflow enables developers to run fast, incremental security scans on their codebase. By focusing only on the changes made since a specific git reference, it provides a more efficient alternative to full repository scans. The process handles workspace identification, diff generation, secure S3 uploads, and job orchestration via the AWS Security Agent, providing automated polling and reporting of findings directly to the user.

What it does

  • Identifies code changes relative to a specified git reference
  • Generates and uploads diff patches and source code snapshots to S3
  • Orchestrates AWS Security Agent code review jobs
  • Automates status polling for ongoing security scan jobs
  • Aggregates and presents security findings by severity level

When to use it

  • Before committing or pushing code to a repository
  • When performing pre-pull request security checks
  • To quickly validate security fixes in a specific branch
  • When a full repository scan is unnecessary or too time-consuming

Advantages

  • Significantly faster than full repository scans
  • Reduces noise by focusing findings on recent changes
  • Integrates directly into standard developer git workflows
  • Provides automated status updates and reporting

Usage examples

“Run a security scan on my current uncommitted changes.”
The agent identifies the diff against HEAD, uploads the patch, and initiates a targeted security scan.
“Scan the changes in this branch compared to main for security issues.”
The agent calculates the diff between main and the current branch, starts the scan, and polls for results.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/aws/diff-scanning-with-aws-security-agent/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip diff-scanning-with-aws-security-agent.zip -d .agents/skills

Documentation by AWS

AWS Security Agent — Diff Scan

Scan only the code that changed since a git ref. Faster than a full scan — focuses findings on the diff. No prior full scan needed.

Local state

Read .security-agent/config.json for agent_space_id and region. If missing, run the setup-security-agent workflow inline first.

Track scans in .security-agent/scans.json.

Resolving the values you need
PlaceholderHow to resolve
<id> (agent space)config.agent_space_id
<region>config.region (default us-east-1)
<account>aws sts get-caller-identity --query Account --output text
<role-arn>arn:aws:iam::<account>:role/SecurityAgentScanRole
<bucket>security-agent-scans-<account>-<region>
<WORKSPACE_ID>printf '%s' "$(pwd)" | md5sum | cut -c1-12

Workflow

  1. Pre-scan checks. Same as full scan — read config, verify agent space, resolve values, generate workspace ID.

  2. Ask what to scan against:

    • Uncommitted changes → BASE_REF=HEAD (default)

    • Branch vs main → BASE_REF=main

    • Custom ref → user provides

  3. Generate diff (fail fast if empty):

    cd <absolute-workspace-path>
    if [ "$BASE_REF" = "HEAD" ]; then
      git diff HEAD > /tmp/diff.patch
    else
      git diff "$BASE_REF..HEAD" > /tmp/diff.patch
    fi
    [ -s /tmp/diff.patch ] || { echo "No changes vs $BASE_REF"; exit 1; }
  4. Zip the workspace (same exclusions as full scan, 2 GB limit):

    cd <absolute-workspace-path>
    zip -r /tmp/source.zip . \
      -x ".git/*" -x ".security-agent/*" -x "node_modules/*" \
      -x "__pycache__/*" -x ".venv/*" -x "venv/*" \
      -x "dist/*" -x "build/*" -x "target/*" \
      -x ".mypy_cache/*" -x ".pytest_cache/*" -x ".tox/*" \
      -x ".next/*" -x "cdk.out/*" -x ".DS_Store" -x "*.pyc"
  5. Upload both source zip and diff patch:

    SCAN_ID="diff-$(date +%s)-$(openssl rand -hex 3)"
    aws s3 cp /tmp/source.zip s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip --expected-bucket-owner <account>
    aws s3 cp /tmp/diff.patch s3://<bucket>/security-scans/diffs/${SCAN_ID}/diff.patch --expected-bucket-owner <account>
  6. Get or create per-workspace CodeReview (same logic as full scan — lookup config.json → code_reviews[<abs_path>], create if absent):

    aws securityagent create-code-review --agent-space-id <id> --title <title> \
      --service-role <role-arn> \
      --assets sourceCode=[{s3Location=s3://<bucket>/security-scans/source/<WORKSPACE_ID>/source.zip}]
  7. Start the diff job:

    aws securityagent start-code-review-job --agent-space-id <id> --code-review-id <cr-id> \
      --diff-source s3Uri=s3://<bucket>/security-scans/diffs/${SCAN_ID}/diff.patch

    If ResourceNotFoundException: recreate CodeReview and retry.

  8. Capture codeReviewJobId. Persist to scans.json with scan_type: "DIFF" and base_ref.

  9. Tell user: "Diff scan started. Takes a few minutes. I'll check every 2 minutes — say 'stop polling' to opt out."

  10. Poll every 2 minutes:

    aws securityagent batch-get-code-review-jobs --agent-space-id <id> --code-review-job-ids <job_id>

    Only respond when status changes. On COMPLETED → fetch findings.

  11. Findings: same presentation as full scan — grouped by severity, report written to .security-agent/findings-{scan_id}.md.


Rules

  • Diff scans are standalone — no prior full scan needed

  • Poll every 2 minutes, not faster

  • Default to BASE_REF=HEAD if user doesn't specify

  • Title: diff-<git-branch>-<timestamp> (no spaces)

  • If diff is empty, tell user and stop — don't start a scan

Files

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs a command-line tool

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
AWS
Publisher
AWS (Official)
Source
aws/agent-toolkit-for-aws · plugins/aws-agents-for-devsecops/skills/diff-scanning-with-aws-security-agent · commit 0a218f8
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • NOTICE (added by AutoGineer from NOTICE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by AWS.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download diff-scanning-with-aws-security-agent.zip