
AI Security Best Practices
AI changes the application layer, not the fundamentals of security. Explore how defense in depth, from cloud infrastructure and IAM to AI red teaming, helps build resilient AI applications on AWS.
Securing AI Applications on AWS: A Practical Defense-in-Depth Approach
Generative AI is transforming how we build software. Organizations are rapidly adopting large language models (LLMs), retrieval-augmented generation (RAG), AI agents, and Model Context Protocol (MCP) servers to build increasingly autonomous applications.
While these technologies unlock tremendous opportunities, they also introduce a new set of security risks. Many of these threats are unique to AI, while others are familiar cloud security problems that become even more critical in AI workloads.
In this article, we'll examine the major security layers of an AI application and discuss practical approaches to securing each one.
Cloud Infrastructure
AI applications ultimately run on cloud infrastructure.
Whether your application is deployed on Amazon ECS, Amazon EKS, AWS Lambda, or Amazon EC2, it still depends on traditional cloud resources such as:
- Compute
- Databases
- Object storage
- Block storage
- Networking
- Identity services
Modern AI systems also introduce AI-native infrastructure such as:
- RAG pipelines
- Vector databases
- MCP servers
- Model hosting endpoints
A vulnerability in any of these components can compromise the entire application.
The first layer of defense is continuous configuration monitoring, commonly known as Cloud Security Posture Management (CSPM).
The idea is straightforward:
Continuously evaluate cloud resources against established security best practices, such as the AWS Well-Architected Framework Security Pillar, CIS Benchmarks, or organizational policies. Whenever a resource drifts from its desired secure configuration, flag it for remediation.
Examples include:
- Public S3 buckets
- Overly permissive security groups
- Unencrypted storage
- Disabled logging
- Excessive IAM permissions
CSPM Solutions
On AWS, AWS Security Hub provides native CSPM capabilities. If you prefer an open-source approach, Prowler is an excellent alternative. In fact, Prowler is the engine we use in T12 to power our CSPM capabilities.
Identity and Access Management (IAM)
Identity is one of the most important security layers in AI systems.
There are two primary categories of identities:
- Human users and services that deploy and manage AI infrastructure
- AI agents that are granted permissions to perform autonomous tasks
Although their purposes differ, the security principles remain the same:
- Follow the Principle of Least Privilege (PoLP)
- Use temporary credentials whenever possible
- Audit all actions
- Remove unused identities and permissions
In the cloud security industry, solutions that help organizations implement these practices are collectively referred to as Cloud Infrastructure Entitlement Management (CIEM).
Of these practices, implementing the Principle of Least Privilege is typically the most challenging**.** User & Application requirements evolve over time, making manually maintained IAM policies increasingly difficult to manage. Application requirements evolve over time, making manually maintained IAM policies increasingly difficult to manage.
CIEM Solutions
On AWS, IAM Access Analyzer helps generate least-privilege policies based on observed permissions usage.
While open-source tools such as PMapper can help analyze IAM permissions and identify privilege escalation paths, there are currently few open-source solutions that provide comprehensive CIEM capabilities. For this reason, we implemented T12's CIEM module in-house.
Supply Chain Security
AI applications rely heavily on external software and data.
Typical dependencies include:
- Open-source packages
- AI frameworks
- Foundation models
- Training datasets
Each dependency expands the application's attack surface.
Attackers may attempt to introduce malicious packages, poisoned datasets, compromised models, or backdoored AI libraries into the software supply chain. Once incorporated, these artifacts may influence model behavior or provide attackers with persistent access.
Reducing supply chain risk begins with basic hygiene:
- Minimize unnecessary third-party dependencies
- Download artifacts only from trusted sources
- Pin dependency versions
- Verify publisher authenticity
Since modern applications inevitably depend on external software, automated validation becomes essential.
Two important practices are:
Software Bill of Materials (SBOM)
An SBOM provides a complete inventory of all software components used by an application.
Software Composition Analysis (SCA)
SCA tools continuously analyze those dependencies for known vulnerabilities, malicious packages, licensing issues, and supply chain risks.
In addition, release artifacts should be digitally signed to ensure they cannot be modified after the build process.
Ideally, SBOM generation, SCA scanning, and code signing should all be integrated directly into the CI/CD pipeline.
AI Interfaces
AI interfaces are where users interact with AI systems.
Examples include:
- Chatbots
- Agent APIs
- MCP endpoints
- Internal AI assistants
These interfaces introduce an entirely new class of attacks.
One well-known example is prompt injection, where carefully crafted prompts manipulate model behavior or bypass intended safeguards.
Another risk is indirect prompt injection, where malicious instructions are embedded inside external content such as documents, websites, emails, or retrieved knowledge base entries.
For autonomous agents, persistence becomes an additional concern.
Unlike traditional chat interactions, AI agents often maintain memory and can write to databases or other systems. If attackers convince an agent to store malicious data, that poisoned information may influence future interactions long after the original attack has ended.
Mitigating these threats requires multiple layers of protection, including:
- Input validation and sanitization
- Output filtering
- Rate limiting
- Human approval for sensitive actions
- Memory validation
- Tool access restrictions
- Retrieval validation
- Secondary model validation for high-risk prompts
No single control is sufficient.
Defense in depth remains just as important for AI systems as it has always been for traditional applications.
Red Teaming AI Applications
Runtime protections help defend production systems, but they cannot guarantee every attack path has been considered.
A proactive approach is AI red teaming.
Rather than testing only the LLM, red teaming evaluates the complete application, including:
- Prompt handling
- Business logic
- Agent workflows
- Tool usage
- RAG pipelines
- Memory systems
- Multi-model orchestration
This provides a much more realistic assessment of how an attacker might compromise the application.
Automated AI red teaming should become a regular part of the development lifecycle in the same way penetration testing has become standard practice for web applications.
AI Red Teaming Solutions
There is currently no single AWS native service dedicated to comprehensive AI red teaming. Open-source frameworks such as PyRIT, garak, and DeepTeam can be used to automate adversarial testing of AI applications. DeepTeam provides particularly broad coverage of AI attack scenarios, which is why we chose it as the foundation for T12's AI red teaming module.
Final Thoughts
AI applications introduce new attack vectors, but they do not replace the fundamentals of cloud security.
A secure AI application still depends on secure infrastructure, strong identity management, a trusted software supply chain, hardened interfaces, and continuous testing.
Organizations that treat AI security as a layered discipline, rather than focusing solely on prompt injection, will be far better positioned to build resilient AI systems as the technology continues to evolve.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article