|
| 1 | +# Lambda Service Guide |
| 2 | + |
| 3 | +Lambda is a fully implemented service in LocalStack Explorer. It supports function management, code and configuration updates, synchronous invocation with log output, triggers, versions, and aliases. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- List, create, and delete Lambda functions |
| 8 | +- View function details (configuration, environment variables, layers, architectures) |
| 9 | +- Update function code (zip upload or S3 reference) |
| 10 | +- Update function configuration (handler, runtime, memory, timeout, environment, role) |
| 11 | +- Invoke functions synchronously with JSON payload |
| 12 | +- View invocation results: status code, response payload, function errors, and decoded CloudWatch logs |
| 13 | +- **Triggers**: view all trigger sources for a function |
| 14 | + - **Resource-based policy triggers** (S3, SNS, API Gateway, EventBridge, etc.) — detected from the function's resource policy via `GetPolicy` |
| 15 | + - **Event source mappings** (SQS, DynamoDB Streams, Kinesis, etc.) — with create and delete support |
| 16 | +- Browse function versions |
| 17 | +- Browse function aliases |
| 18 | +- Search/filter functions by name |
| 19 | +- Active service detection: Lambda appears greyed out in the UI when not running on LocalStack |
| 20 | + |
| 21 | +## API Endpoints |
| 22 | + |
| 23 | +All endpoints are prefixed with `/api/lambda`. |
| 24 | + |
| 25 | +### Functions |
| 26 | + |
| 27 | +| Method | Path | Description | Request | Response | |
| 28 | +|--------|-------------------------------|--------------------------|--------------------------------|--------------------------------| |
| 29 | +| GET | `/` | List functions | `?marker=string` | `{ functions: [...] }` | |
| 30 | +| POST | `/` | Create function | `CreateFunctionBody` | `{ message: string }` | |
| 31 | +| GET | `/:functionName` | Get function detail | -- | `FunctionDetail` | |
| 32 | +| PUT | `/:functionName/code` | Update function code | `{ zipFile?, s3Bucket?, s3Key? }` | `{ message: string }` | |
| 33 | +| PUT | `/:functionName/config` | Update function config | `UpdateFunctionConfigBody` | `{ message: string }` | |
| 34 | +| DELETE | `/:functionName` | Delete function | -- | `{ success: boolean }` | |
| 35 | + |
| 36 | +### Invocation |
| 37 | + |
| 38 | +| Method | Path | Description | Request | Response | |
| 39 | +|--------|-------------------------------|--------------------------|--------------------------------|--------------------------------| |
| 40 | +| POST | `/:functionName/invoke` | Invoke function | `{ payload?, invocationType? }` | `InvokeFunctionResponse` | |
| 41 | + |
| 42 | +### Triggers |
| 43 | + |
| 44 | +| Method | Path | Description | Request | Response | |
| 45 | +|--------|--------------------------------------------|--------------------------------|--------------------------------------------------|-------------------------------------------| |
| 46 | +| GET | `/:functionName/triggers` | List all triggers | `?marker=string` | `{ eventSourceMappings, policyTriggers }` | |
| 47 | +| POST | `/:functionName/event-source-mappings` | Create event source mapping | `{ eventSourceArn, batchSize?, enabled?, ... }` | `{ message, uuid }` | |
| 48 | +| DELETE | `/event-source-mappings/:uuid` | Delete event source mapping | -- | `{ success: boolean }` | |
| 49 | + |
| 50 | +The `GET /:functionName/triggers` endpoint combines two data sources: |
| 51 | +- **Event source mappings** — Lambda's `ListEventSourceMappings` (SQS queues, DynamoDB Streams, Kinesis streams) |
| 52 | +- **Policy triggers** — parsed from the function's resource-based policy via `GetPolicy` (S3 bucket notifications, SNS topics, API Gateway, EventBridge rules, etc.) |
| 53 | + |
| 54 | +### Versions & Aliases |
| 55 | + |
| 56 | +| Method | Path | Description | Request | Response | |
| 57 | +|--------|-------------------------------|--------------------------|--------------------------------|--------------------------------| |
| 58 | +| GET | `/:functionName/versions` | List versions | `?marker=string` | `{ versions: [...] }` | |
| 59 | +| GET | `/:functionName/aliases` | List aliases | `?marker=string` | `{ aliases: [...] }` | |
| 60 | + |
| 61 | +### Request/Response Examples |
| 62 | + |
| 63 | +**List functions:** |
| 64 | + |
| 65 | +```bash |
| 66 | +curl http://localhost:3001/api/lambda |
| 67 | +``` |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "functions": [ |
| 72 | + { |
| 73 | + "functionName": "my-function", |
| 74 | + "functionArn": "arn:aws:lambda:us-east-1:000000000000:function:my-function", |
| 75 | + "runtime": "nodejs20.x", |
| 76 | + "handler": "index.handler", |
| 77 | + "codeSize": 284, |
| 78 | + "lastModified": "2024-01-15T10:30:00.000+0000", |
| 79 | + "memorySize": 128, |
| 80 | + "timeout": 30 |
| 81 | + } |
| 82 | + ] |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +**Create function:** |
| 87 | + |
| 88 | +```bash |
| 89 | +curl -X POST http://localhost:3001/api/lambda \ |
| 90 | + -H "Content-Type: application/json" \ |
| 91 | + -d '{ |
| 92 | + "functionName": "my-function", |
| 93 | + "runtime": "nodejs20.x", |
| 94 | + "handler": "index.handler", |
| 95 | + "role": "arn:aws:iam::000000000000:role/lambda-role", |
| 96 | + "code": { "zipFile": "<base64-encoded-zip>" }, |
| 97 | + "memorySize": 128, |
| 98 | + "timeout": 30 |
| 99 | + }' |
| 100 | +``` |
| 101 | + |
| 102 | +```json |
| 103 | +{ "message": "Function 'my-function' created successfully" } |
| 104 | +``` |
| 105 | + |
| 106 | +**Invoke function:** |
| 107 | + |
| 108 | +```bash |
| 109 | +curl -X POST http://localhost:3001/api/lambda/my-function/invoke \ |
| 110 | + -H "Content-Type: application/json" \ |
| 111 | + -d '{ |
| 112 | + "payload": "{\"key\": \"value\"}", |
| 113 | + "invocationType": "RequestResponse" |
| 114 | + }' |
| 115 | +``` |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "statusCode": 200, |
| 120 | + "payload": "{\"statusCode\":200,\"body\":\"hello\"}", |
| 121 | + "logResult": "START RequestId: ...\nEND RequestId: ...\n" |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +**Get function detail:** |
| 126 | + |
| 127 | +```bash |
| 128 | +curl http://localhost:3001/api/lambda/my-function |
| 129 | +``` |
| 130 | + |
| 131 | +```json |
| 132 | +{ |
| 133 | + "functionName": "my-function", |
| 134 | + "functionArn": "arn:aws:lambda:us-east-1:000000000000:function:my-function", |
| 135 | + "runtime": "nodejs20.x", |
| 136 | + "handler": "index.handler", |
| 137 | + "role": "arn:aws:iam::000000000000:role/lambda-role", |
| 138 | + "codeSize": 284, |
| 139 | + "description": "My Lambda function", |
| 140 | + "timeout": 30, |
| 141 | + "memorySize": 128, |
| 142 | + "lastModified": "2024-01-15T10:30:00.000+0000", |
| 143 | + "codeSha256": "abc123...", |
| 144 | + "version": "$LATEST", |
| 145 | + "environment": { "NODE_ENV": "production" }, |
| 146 | + "architectures": ["x86_64"], |
| 147 | + "layers": [], |
| 148 | + "packageType": "Zip" |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +**List triggers:** |
| 153 | + |
| 154 | +```bash |
| 155 | +curl http://localhost:3001/api/lambda/my-function/triggers |
| 156 | +``` |
| 157 | + |
| 158 | +```json |
| 159 | +{ |
| 160 | + "eventSourceMappings": [ |
| 161 | + { |
| 162 | + "uuid": "abc-123", |
| 163 | + "eventSourceArn": "arn:aws:sqs:us-east-1:000000000000:my-queue", |
| 164 | + "state": "Enabled", |
| 165 | + "batchSize": 10 |
| 166 | + } |
| 167 | + ], |
| 168 | + "policyTriggers": [ |
| 169 | + { |
| 170 | + "sid": "AllowS3Invoke", |
| 171 | + "service": "s3.amazonaws.com", |
| 172 | + "sourceArn": "arn:aws:s3:::my-bucket" |
| 173 | + } |
| 174 | + ] |
| 175 | +} |
| 176 | +``` |
| 177 | + |
| 178 | +**Create event source mapping:** |
| 179 | + |
| 180 | +```bash |
| 181 | +curl -X POST http://localhost:3001/api/lambda/my-function/event-source-mappings \ |
| 182 | + -H "Content-Type: application/json" \ |
| 183 | + -d '{ |
| 184 | + "eventSourceArn": "arn:aws:sqs:us-east-1:000000000000:my-queue", |
| 185 | + "batchSize": 10, |
| 186 | + "enabled": true |
| 187 | + }' |
| 188 | +``` |
| 189 | + |
| 190 | +```json |
| 191 | +{ "message": "Event source mapping created successfully", "uuid": "abc-123" } |
| 192 | +``` |
| 193 | + |
| 194 | +**Delete function:** |
| 195 | + |
| 196 | +```bash |
| 197 | +curl -X DELETE http://localhost:3001/api/lambda/my-function |
| 198 | +``` |
| 199 | + |
| 200 | +```json |
| 201 | +{ "success": true } |
| 202 | +``` |
| 203 | + |
| 204 | +## Error Handling |
| 205 | + |
| 206 | +| Error | HTTP Status | Code | |
| 207 | +|---------------------------------|-------------|----------------------| |
| 208 | +| Function not found | 404 | `FUNCTION_NOT_FOUND` | |
| 209 | +| Function already exists / in use | 409 | `FUNCTION_CONFLICT` | |
| 210 | +| Event source mapping not found | 404 | `EVENT_SOURCE_MAPPING_NOT_FOUND` | |
| 211 | +| Invalid parameter value | 400 | `INVALID_PARAMETER` | |
| 212 | +| Rate limit exceeded | 429 | `TOO_MANY_REQUESTS` | |
| 213 | +| AWS service error | 502 | `SERVICE_ERROR` | |
| 214 | + |
| 215 | +## UI Components |
| 216 | + |
| 217 | +### Function List (`/lambda`) |
| 218 | + |
| 219 | +- Searchable table with columns: Name, Runtime, Memory, Timeout, Last Modified |
| 220 | +- Function name links to detail view |
| 221 | +- Create button opens a dialog with fields for name, runtime, handler, role, memory, timeout, and optional zip upload |
| 222 | +- Per-row delete button with confirmation dialog |
| 223 | + |
| 224 | +### Function Detail (`/lambda/:functionName`) |
| 225 | + |
| 226 | +Five tabs: |
| 227 | + |
| 228 | +1. **Configuration** — attribute grid (runtime, handler, role, memory, timeout, code size, state, package type, architectures, SHA256) and environment variables table |
| 229 | +2. **Invoke** — JSON payload textarea, invocation type selector (RequestResponse, Event, DryRun), result panel with status code, payload, error, and decoded log output |
| 230 | +3. **Triggers** — two sections: |
| 231 | + - **Resource-Based Policy Triggers** — read-only table showing services (S3, SNS, API Gateway, etc.) authorized to invoke the function, with source ARN and policy statement ID. Detected automatically from the function's resource-based policy. |
| 232 | + - **Event Source Mappings** — table of SQS/DynamoDB Streams/Kinesis mappings with state, batch size, and last modified. Supports creating new mappings (event source ARN + batch size) and deleting existing ones with confirmation dialog. |
| 233 | +4. **Versions** — table of published versions with version number, ARN, runtime, and last modified date |
| 234 | +5. **Aliases** — table of aliases with name, ARN, function version, and description |
| 235 | + |
| 236 | +## Backend Architecture |
| 237 | + |
| 238 | +The Lambda plugin follows the standard service plugin pattern: |
| 239 | + |
| 240 | +``` |
| 241 | +packages/backend/src/plugins/lambda/ |
| 242 | +├── index.ts # Plugin registration (5 lines) |
| 243 | +├── routes.ts # 12 Fastify routes |
| 244 | +├── service.ts # LambdaService class wrapping @aws-sdk/client-lambda |
| 245 | +└── schemas.ts # TypeBox request/response schemas |
| 246 | +``` |
| 247 | + |
| 248 | +The `LambdaService` class maps AWS SDK exceptions to `AppError` instances with appropriate HTTP status codes via a centralized `mapLambdaError` function. |
0 commit comments