How do you secure AWS Lambda functions?
Instruction: Explain some methods to secure an AWS Lambda function.
Updated
Official answer
Give the function an execution role that grants only the actions and resources it needs. Separately control who or what can invoke it through the caller's identity permissions, supported resource policies and the API's authentication/authorization. A least-privilege execution role does not itself authenticate an HTTP client.
Store credentials and API keys in an appropriate managed secret store such as Secrets Manager. Environment variables can carry non-secret settings or secret identifiers. Encryption at rest does not stop authorized code or overly privileged operators from reading a secret, and secrets must not appear in logs or error responses.
Connect the function to a VPC when it needs private resources. Scope security groups and routes, and provide only required outbound connectivity. Attaching a function to a public subnet does not give it a public IP or internet access; VPC attachment is not a substitute for controlling invocation access.
Validate untrusted input, parameterize database operations, maintain dependencies and bound resource use. Protect deployment permissions and artifacts. Monitor configuration changes and denied access; configure the required CloudTrail data events rather than assuming every invocation is logged by default.
Test allowed and denied access, secret rotation, malformed input and dependency failures in an isolated environment. Security is a property of the complete configured workflow, not a guarantee supplied by one AWS feature.
Execution roles, secret guidance, VPC behavior, CloudTrail coverage