or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

account-settings.mdalias-version-management.mdclient-management.mdconcurrency-performance.mdevent-source-mapping.mdfunction-invocation.mdfunction-management.mdfunction-url-management.mdhigh-level-invocation.mdindex.mdlayer-management.mdpermissions-policies.mdruntime-management.mdsecurity-code-signing.mdtagging.mdwaiters-polling.md

layer-management.mddocs/

0

# Layer Management

1

2

Comprehensive layer lifecycle operations including publishing, versioning, permission management, and deletion of Lambda layers for sharing common code and dependencies across functions.

3

4

## Capabilities

5

6

### Layer Publishing

7

8

Creates a Lambda layer from a ZIP archive containing libraries, custom runtimes, or other dependencies.

9

10

```java { .api }

11

/**

12

* Creates a Lambda layer from ZIP archive containing dependencies or libraries

13

* @param request Layer publishing parameters including content, compatible runtimes, and description

14

* @return PublishLayerVersionResult containing layer version details and download information

15

* @throws ServiceException if service encounters an error

16

* @throws InvalidParameterValueException if parameters are invalid

17

* @throws ResourceConflictException if layer limit exceeded

18

*/

19

PublishLayerVersionResult publishLayerVersion(PublishLayerVersionRequest request);

20

21

public class PublishLayerVersionRequest {

22

/** Layer name (required) - 1-64 characters, pattern: [a-zA-Z0-9-_]+ */

23

private String layerName;

24

/** Layer description (optional) - up to 256 characters */

25

private String description;

26

/** Layer content (required) - ZIP file up to 50 MB */

27

private LayerVersionContentInput content;

28

/** Compatible runtimes (optional) - list of supported runtime environments */

29

private List<Runtime> compatibleRuntimes;

30

/** License information (optional) - up to 512 characters */

31

private String licenseInfo;

32

/** Compatible architectures (optional) - x86_64, arm64 */

33

private List<Architecture> compatibleArchitectures;

34

}

35

36

public class LayerVersionContentInput {

37

/** S3 bucket containing ZIP file (optional) */

38

private String s3Bucket;

39

/** S3 object key (optional) */

40

private String s3Key;

41

/** S3 object version (optional) */

42

private String s3ObjectVersion;

43

/** Base64-encoded ZIP content (optional) - max 50 MB */

44

private ByteBuffer zipFile;

45

}

46

47

public class PublishLayerVersionResult {

48

/** Layer version content information */

49

private LayerVersionContentOutput content;

50

/** Layer ARN */

51

private String layerArn;

52

/** Layer version ARN */

53

private String layerVersionArn;

54

/** Layer description */

55

private String description;

56

/** Creation timestamp */

57

private String createdDate;

58

/** Version number */

59

private Long version;

60

/** Compatible runtimes */

61

private List<Runtime> compatibleRuntimes;

62

/** License information */

63

private String licenseInfo;

64

/** Compatible architectures */

65

private List<Architecture> compatibleArchitectures;

66

}

67

68

public class LayerVersionContentOutput {

69

/** Download location (valid for 10 minutes) */

70

private String location;

71

/** SHA256 hash of layer content */

72

private String codeSha256;

73

/** Layer content size in bytes */

74

private Long codeSize;

75

/** Signing profile version ARN */

76

private String signingProfileVersionArn;

77

/** Signing job ARN */

78

private String signingJobArn;

79

}

80

```

81

82

### Layer Version Retrieval

83

84

Retrieves information about a specific layer version including download location.

85

86

```java { .api }

87

/**

88

* Retrieves layer version information with download link (valid 10 minutes)

89

* @param request Layer version retrieval parameters including layer name and version

90

* @return GetLayerVersionResult containing layer details and download information

91

* @throws ResourceNotFoundException if layer version does not exist

92

* @throws ServiceException if service encounters an error

93

*/

94

GetLayerVersionResult getLayerVersion(GetLayerVersionRequest request);

95

96

public class GetLayerVersionRequest {

97

/** Layer name (required) - name or ARN */

98

private String layerName;

99

/** Version number (required) */

100

private Long versionNumber;

101

}

102

103

public class GetLayerVersionResult {

104

/** Layer version content information */

105

private LayerVersionContentOutput content;

106

/** Layer ARN */

107

private String layerArn;

108

/** Layer version ARN */

109

private String layerVersionArn;

110

/** Layer description */

111

private String description;

112

/** Creation timestamp */

113

private String createdDate;

114

/** Version number */

115

private Long version;

116

/** Compatible runtimes */

117

private List<Runtime> compatibleRuntimes;

118

/** License information */

119

private String licenseInfo;

120

/** Compatible architectures */

121

private List<Architecture> compatibleArchitectures;

122

}

123

```

124

125

### Layer Version Retrieval by ARN

126

127

Retrieves layer version information using the layer version ARN.

128

129

```java { .api }

130

/**

131

* Retrieves layer version information by ARN

132

* @param request Layer version ARN retrieval parameters

133

* @return GetLayerVersionByArnResult containing layer details

134

* @throws ResourceNotFoundException if layer version does not exist

135

* @throws ServiceException if service encounters an error

136

*/

137

GetLayerVersionByArnResult getLayerVersionByArn(GetLayerVersionByArnRequest request);

138

139

public class GetLayerVersionByArnRequest {

140

/** Layer version ARN (required) */

141

private String arn;

142

}

143

144

public class GetLayerVersionByArnResult {

145

/** Layer version content information */

146

private LayerVersionContentOutput content;

147

/** Layer ARN */

148

private String layerArn;

149

/** Layer version ARN */

150

private String layerVersionArn;

151

/** Layer description */

152

private String description;

153

/** Creation timestamp */

154

private String createdDate;

155

/** Version number */

156

private Long version;

157

/** Compatible runtimes */

158

private List<Runtime> compatibleRuntimes;

159

/** License information */

160

private String licenseInfo;

161

/** Compatible architectures */

162

private List<Architecture> compatibleArchitectures;

163

}

164

```

165

166

### Layer Version Deletion

167

168

Deletes a specific layer version. Content remains until no functions reference it.

169

170

```java { .api }

171

/**

172

* Deletes a layer version (content copy remains until no function references)

173

* @param request Layer version deletion parameters including layer name and version

174

* @return DeleteLayerVersionResult indicating successful deletion

175

* @throws ServiceException if service encounters an error

176

* @throws ResourceNotFoundException if layer version does not exist

177

*/

178

DeleteLayerVersionResult deleteLayerVersion(DeleteLayerVersionRequest request);

179

180

public class DeleteLayerVersionRequest {

181

/** Layer name (required) - name or ARN */

182

private String layerName;

183

/** Version number (required) */

184

private Long versionNumber;

185

}

186

187

public class DeleteLayerVersionResult {

188

// Empty result indicating successful deletion

189

}

190

```

191

192

### Layer Listing

193

194

Lists Lambda layers with information about the latest version.

195

196

```java { .api }

197

/**

198

* Lists Lambda layers with latest version information

199

* @param request Layer listing parameters including compatible runtime filter and pagination

200

* @return ListLayersResult containing layer list with latest versions

201

* @throws ServiceException if service encounters an error

202

*/

203

ListLayersResult listLayers(ListLayersRequest request);

204

205

public class ListLayersRequest {

206

/** Compatible runtime filter (optional) */

207

private Runtime compatibleRuntime;

208

/** Pagination marker (optional) */

209

private String marker;

210

/** Maximum items to return (optional, range: 1-50) */

211

private Integer maxItems;

212

/** Compatible architecture filter (optional) */

213

private Architecture compatibleArchitecture;

214

}

215

216

public class ListLayersResult {

217

/** Pagination marker for next page */

218

private String nextMarker;

219

/** List of layers with latest version info */

220

private List<LayersListItem> layers;

221

}

222

223

public class LayersListItem {

224

/** Layer name */

225

private String layerName;

226

/** Layer ARN */

227

private String layerArn;

228

/** Latest layer version information */

229

private LayerVersionsListItem latestMatchingVersion;

230

}

231

232

public class LayerVersionsListItem {

233

/** Layer version ARN */

234

private String layerVersionArn;

235

/** Version number */

236

private Long version;

237

/** Layer description */

238

private String description;

239

/** Creation timestamp */

240

private String createdDate;

241

/** Compatible runtimes */

242

private List<Runtime> compatibleRuntimes;

243

/** License information */

244

private String licenseInfo;

245

/** Compatible architectures */

246

private List<Architecture> compatibleArchitectures;

247

}

248

```

249

250

### Layer Version Listing

251

252

Lists all versions for a specific layer.

253

254

```java { .api }

255

/**

256

* Lists all versions for a specific layer

257

* @param request Layer version listing parameters including layer name and pagination

258

* @return ListLayerVersionsResult containing version list and pagination info

259

* @throws ResourceNotFoundException if layer does not exist

260

* @throws ServiceException if service encounters an error

261

*/

262

ListLayerVersionsResult listLayerVersions(ListLayerVersionsRequest request);

263

264

public class ListLayerVersionsRequest {

265

/** Layer name (required) - name or ARN */

266

private String layerName;

267

/** Compatible runtime filter (optional) */

268

private Runtime compatibleRuntime;

269

/** Pagination marker (optional) */

270

private String marker;

271

/** Maximum items to return (optional, range: 1-50) */

272

private Integer maxItems;

273

/** Compatible architecture filter (optional) */

274

private Architecture compatibleArchitecture;

275

}

276

277

public class ListLayerVersionsResult {

278

/** Pagination marker for next page */

279

private String nextMarker;

280

/** List of layer versions */

281

private List<LayerVersionsListItem> layerVersions;

282

}

283

```

284

285

## Layer Permission Management

286

287

### Add Layer Version Permission

288

289

Grants permission for accounts or organizations to use a layer version.

290

291

```java { .api }

292

/**

293

* Grants layer version usage permission to AWS accounts or organizations

294

* @param request Permission grant parameters including principal and action

295

* @return AddLayerVersionPermissionResult containing statement ID and policy

296

* @throws ResourceNotFoundException if layer version does not exist

297

* @throws ResourceConflictException if statement ID already exists

298

* @throws PolicyLengthExceededException if policy exceeds size limit

299

*/

300

AddLayerVersionPermissionResult addLayerVersionPermission(AddLayerVersionPermissionRequest request);

301

302

public class AddLayerVersionPermissionRequest {

303

/** Layer name (required) - name or ARN */

304

private String layerName;

305

/** Version number (required) */

306

private Long versionNumber;

307

/** Statement ID (required) - unique identifier for permission statement */

308

private String statementId;

309

/** Action (required) - typically "lambda:GetLayerVersion" */

310

private String action;

311

/** Principal (required) - AWS account ID, organization ID, or "*" */

312

private String principal;

313

/** Organization ID (optional) - restrict to specific organization */

314

private String organizationId;

315

/** Revision ID for optimistic locking (optional) */

316

private String revisionId;

317

}

318

319

public class AddLayerVersionPermissionResult {

320

/** Statement ID */

321

private String statementId;

322

/** Updated resource policy */

323

private String statement;

324

/** Revision ID */

325

private String revisionId;

326

}

327

```

328

329

### Remove Layer Version Permission

330

331

Revokes permission for accounts or organizations to use a layer version.

332

333

```java { .api }

334

/**

335

* Revokes layer version usage permission

336

* @param request Permission revocation parameters including statement ID

337

* @return RemoveLayerVersionPermissionResult indicating successful removal

338

* @throws ResourceNotFoundException if layer version or statement does not exist

339

* @throws ServiceException if service encounters an error

340

*/

341

RemoveLayerVersionPermissionResult removeLayerVersionPermission(RemoveLayerVersionPermissionRequest request);

342

343

public class RemoveLayerVersionPermissionRequest {

344

/** Layer name (required) - name or ARN */

345

private String layerName;

346

/** Version number (required) */

347

private Long versionNumber;

348

/** Statement ID (required) - identifier of permission statement to remove */

349

private String statementId;

350

/** Revision ID for optimistic locking (optional) */

351

private String revisionId;

352

}

353

354

public class RemoveLayerVersionPermissionResult {

355

// Empty result indicating successful removal

356

}

357

```

358

359

### Get Layer Version Policy

360

361

Retrieves the resource-based policy for a layer version.

362

363

```java { .api }

364

/**

365

* Retrieves resource-based IAM policy for layer version

366

* @param request Policy retrieval parameters including layer name and version

367

* @return GetLayerVersionPolicyResult containing policy document and revision ID

368

* @throws ResourceNotFoundException if layer version or policy does not exist

369

* @throws ServiceException if service encounters an error

370

*/

371

GetLayerVersionPolicyResult getLayerVersionPolicy(GetLayerVersionPolicyRequest request);

372

373

public class GetLayerVersionPolicyRequest {

374

/** Layer name (required) - name or ARN */

375

private String layerName;

376

/** Version number (required) */

377

private Long versionNumber;

378

}

379

380

public class GetLayerVersionPolicyResult {

381

/** Resource-based policy document */

382

private String policy;

383

/** Revision ID */

384

private String revisionId;

385

}

386

```

387

388

## Usage Examples

389

390

### Publishing a Layer

391

392

```java

393

AWSLambda lambdaClient = AWSLambdaClientBuilder.defaultClient();

394

395

// Upload layer from S3

396

LayerVersionContentInput content = new LayerVersionContentInput()

397

.withS3Bucket("my-bucket")

398

.withS3Key("layers/numpy-layer.zip");

399

400

PublishLayerVersionRequest request = new PublishLayerVersionRequest()

401

.withLayerName("numpy-scipy-layer")

402

.withDescription("NumPy and SciPy libraries for Python 3.9")

403

.withContent(content)

404

.withCompatibleRuntimes(Runtime.Python39, Runtime.Python38)

405

.withCompatibleArchitectures(Architecture.X86_64)

406

.withLicenseInfo("MIT");

407

408

PublishLayerVersionResult result = lambdaClient.publishLayerVersion(request);

409

System.out.println("Published layer version: " + result.getVersion());

410

System.out.println("Layer ARN: " + result.getLayerVersionArn());

411

```

412

413

### Publishing Layer from Local File

414

415

```java

416

// Read ZIP file into memory

417

Path zipPath = Paths.get("my-layer.zip");

418

byte[] zipContent = Files.readAllBytes(zipPath);

419

420

LayerVersionContentInput content = new LayerVersionContentInput()

421

.withZipFile(ByteBuffer.wrap(zipContent));

422

423

PublishLayerVersionRequest request = new PublishLayerVersionRequest()

424

.withLayerName("my-utilities-layer")

425

.withDescription("Common utility functions")

426

.withContent(content)

427

.withCompatibleRuntimes(Runtime.Java11, Runtime.Java8al2)

428

.withLicenseInfo("Apache-2.0");

429

430

PublishLayerVersionResult result = lambdaClient.publishLayerVersion(request);

431

```

432

433

### Granting Layer Access

434

435

```java

436

// Grant access to specific AWS account

437

AddLayerVersionPermissionRequest request = new AddLayerVersionPermissionRequest()

438

.withLayerName("my-shared-layer")

439

.withVersionNumber(1L)

440

.withStatementId("account-123456789012")

441

.withAction("lambda:GetLayerVersion")

442

.withPrincipal("123456789012");

443

444

AddLayerVersionPermissionResult result = lambdaClient.addLayerVersionPermission(request);

445

446

// Grant public access (use with caution)

447

AddLayerVersionPermissionRequest publicRequest = new AddLayerVersionPermissionRequest()

448

.withLayerName("my-public-layer")

449

.withVersionNumber(1L)

450

.withStatementId("public-access")

451

.withAction("lambda:GetLayerVersion")

452

.withPrincipal("*");

453

454

lambdaClient.addLayerVersionPermission(publicRequest);

455

```

456

457

### Listing Layers by Runtime

458

459

```java

460

ListLayersRequest request = new ListLayersRequest()

461

.withCompatibleRuntime(Runtime.Python39)

462

.withCompatibleArchitecture(Architecture.X86_64)

463

.withMaxItems(20);

464

465

ListLayersResult result = lambdaClient.listLayers(request);

466

for (LayersListItem layer : result.getLayers()) {

467

LayerVersionsListItem latest = layer.getLatestMatchingVersion();

468

System.out.println("Layer: " + layer.getLayerName() +

469

" (v" + latest.getVersion() + ")");

470

System.out.println("Description: " + latest.getDescription());

471

}

472

```

473

474

### Downloading Layer Content

475

476

```java

477

GetLayerVersionRequest request = new GetLayerVersionRequest()

478

.withLayerName("my-layer")

479

.withVersionNumber(1L);

480

481

GetLayerVersionResult result = lambdaClient.getLayerVersion(request);

482

String downloadUrl = result.getContent().getLocation();

483

484

// URL is valid for 10 minutes - download immediately

485

// Use HTTP client to download from the URL

486

System.out.println("Download URL: " + downloadUrl);

487

System.out.println("SHA256: " + result.getContent().getCodeSha256());

488

```

489

490

## Exception Handling

491

492

Common exceptions when working with layers:

493

494

- **ResourceNotFoundException**: Layer or layer version does not exist

495

- **ResourceConflictException**: Layer limit exceeded or statement ID already exists

496

- **InvalidParameterValueException**: Invalid layer name, version, or content

497

- **PolicyLengthExceededException**: Resource policy exceeds maximum size

498

- **ServiceException**: General service errors

499

- **TooManyRequestsException**: Rate limiting exceeded

500

501

## Best Practices

502

503

### Layer Design

504

- Keep layers focused on specific functionality or dependencies

505

- Include compatible runtimes and architectures in layer metadata

506

- Use meaningful layer names and descriptions

507

- Document layer contents and usage instructions

508

509

### Version Management

510

- Use semantic versioning in layer descriptions

511

- Test layer compatibility with target function runtimes

512

- Keep layer size under 50 MB (unzipped: 250 MB)

513

- Delete unused layer versions to manage costs

514

515

### Permission Management

516

- Grant minimal necessary permissions for layer access

517

- Use organization IDs to restrict access within your organization

518

- Regularly audit layer permissions and usage

519

- Avoid public access unless absolutely necessary

520

521

### Content Organization

522

- Follow runtime-specific directory structures (/opt for Lambda)

523

- Include proper file permissions in ZIP archives

524

- Test layer extraction and loading in target runtime

525

- Document layer dependencies and requirements