Loading...
Loading...
AWS development best practices for Lambda, SAM, CDK, DynamoDB, IAM, and serverless architecture using Infrastructure as Code.
npx skill4agent add mindrally/skills aws-development// Use ES modules and typed handlers
import { APIGatewayProxyHandler } from 'aws-lambda';
export const handler: APIGatewayProxyHandler = async (event) => {
try {
// Validate input at function start
if (!event.body) {
return { statusCode: 400, body: JSON.stringify({ error: 'Missing body' }) };
}
// Business logic here
return { statusCode: 200, body: JSON.stringify({ success: true }) };
} catch (error) {
console.error('Lambda error:', error);
return { statusCode: 500, body: JSON.stringify({ error: 'Internal error' }) };
}
};aws-cdk-libaws_*aws/
├── constructs/ # CDK custom constructs
├── stacks/ # CloudFormation stack definitions
├── functions/ # Lambda function implementations
└── tests/ # Infrastructure testsimport * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws_lambda';
import * as dynamodb from 'aws-cdk-lib/aws_dynamodb';
// Use custom constructs for reusable patterns
export class ApiConstruct extends Construct {
constructor(scope: Construct, id: string, props: ApiProps) {
super(scope, id);
// Implementation
}
}{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:PutItem",
"dynamodb:Query"
],
"Resource": "arn:aws:dynamodb:*:*:table/MyTable"
}
]
}AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 30
Runtime: nodejs20.x
Architectures:
- arm64
Tracing: Active
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: index.handler
Events:
Api:
Type: Api
Properties:
Path: /items
Method: GETimport { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { mockClient } from 'aws-sdk-client-mock';
const ddbMock = mockClient(DynamoDBClient);
beforeEach(() => {
ddbMock.reset();
});
test('handler returns items', async () => {
ddbMock.on(QueryCommand).resolves({ Items: [] });
const result = await handler(event);
expect(result.statusCode).toBe(200);
});cdk diffsam validate