Build and deploy a serverless HTTP API on AWS using AWS Lambda behind Amazon API Gateway. Use when the user asks to create a REST or HTTP API, connect a Lambda function to API Gateway, deploy a serverless endpoint or backend, or scaffold a serverless application. Provides an infrastructure-as-code walkthrough (AWS SAM and AWS CDK) with least-privilege IAM, structured logging, sensible timeout and memory settings, and pay-per-request defaults, following AWS Well-Architected serverless best practices.
95%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Ship an HTTP API backed by AWS Lambda behind Amazon API Gateway, defined as
infrastructure-as-code. Follow the working-with-aws guardrails throughout.
template.yaml:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Runtime: python3.12
MemorySize: 256
Timeout: 10
LoggingConfig:
LogFormat: JSON
Resources:
ApiFunction:
Type: AWS::Serverless::Function
Properties:
Handler: app.handler
CodeUri: src/
Events:
Api:
Type: HttpApi
Properties:
Path: /items
Method: GET
Outputs:
ApiUrl:
Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com"Deploy: sam build && sam deploy --guided. SAM creates the HTTP API, the
function, and a scoped execution role automatically.
import { Stack, StackProps, Duration } from "aws-cdk-lib";
import { Construct } from "constructs";
import { HttpApi, HttpMethod } from "aws-cdk-lib/aws-apigatewayv2";
import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
import { Runtime, LoggingFormat } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
export class ServerlessApiStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const fn = new NodejsFunction(this, "ApiFunction", {
runtime: Runtime.NODEJS_20_X,
memorySize: 256,
timeout: Duration.seconds(10),
loggingFormat: LoggingFormat.JSON,
entry: "src/app.ts",
});
const api = new HttpApi(this, "HttpApi");
api.addRoutes({
path: "/items",
methods: [HttpMethod.GET],
integration: new HttpLambdaIntegration("ItemsIntegration", fn),
});
}
}Deploy: cdk deploy. CDK synthesizes least-privilege permissions for the
integrations you declare.
curl https://<api-id>.execute-api.<region>.amazonaws.com/items.If you need help wiring a data store behind the function, load the
choose-a-database skill.
c5551e1
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.