0
# Core Deployment Management
1
2
Primary AWS resource management functions that form the foundation of Zappa's serverless deployment capabilities. These methods handle Lambda function lifecycle, API Gateway deployment, and AWS infrastructure management.
3
4
## Capabilities
5
6
### Lambda Function Management
7
8
Create, update, configure, and delete AWS Lambda functions with comprehensive deployment options.
9
10
```python { .api }
11
def create_lambda_function(
12
self,
13
bucket=None,
14
function_name=None,
15
handler=None,
16
s3_key=None,
17
description="Zappa Deployment",
18
timeout=30,
19
memory_size=512,
20
ephemeral_storage={"Size": 512},
21
publish=True,
22
layers=None,
23
dead_letter_config=None,
24
environment_variables=None,
25
vpc_config=None,
26
**kwargs
27
):
28
"""
29
Create a new Lambda function.
30
31
Parameters:
32
- bucket: str, S3 bucket containing deployment package
33
- function_name: str, name of the Lambda function
34
- handler: str, entry point for the function (module.function)
35
- s3_key: str, S3 key of the deployment package
36
- description: str, function description (default "Zappa Deployment")
37
- timeout: int, function timeout in seconds (1-900)
38
- memory_size: int, memory allocation in MB (128-10240)
39
- ephemeral_storage: dict, ephemeral storage configuration
40
- publish: bool, publish a version of the function
41
- layers: list, ARNs of Lambda layers
42
- dead_letter_config: dict, dead letter queue configuration
43
- environment_variables: dict, environment variables
44
- vpc_config: dict, VPC configuration
45
46
Returns:
47
dict: Lambda function configuration
48
"""
49
```
50
51
```python { .api }
52
def update_lambda_function(
53
self,
54
bucket,
55
function_name,
56
s3_key=None,
57
publish=True,
58
**kwargs
59
):
60
"""
61
Update Lambda function code.
62
63
Parameters:
64
- bucket: str, S3 bucket containing deployment package
65
- function_name: str, name of the function to update
66
- s3_key: str, S3 key of the new deployment package
67
- publish: bool, publish a new version
68
69
Returns:
70
dict: Updated function configuration
71
"""
72
```
73
74
```python { .api }
75
def update_lambda_configuration(
76
self,
77
function_name,
78
timeout=None,
79
memory_size=None,
80
environment_variables=None,
81
vpc_config=None,
82
layers=None,
83
**kwargs
84
):
85
"""
86
Update Lambda function configuration.
87
88
Parameters:
89
- function_name: str, name of the function
90
- timeout: int, function timeout in seconds
91
- memory_size: int, memory allocation in MB
92
- environment_variables: dict, environment variables
93
- vpc_config: dict, VPC configuration
94
- layers: list, ARNs of Lambda layers
95
96
Returns:
97
dict: Updated function configuration
98
"""
99
```
100
101
```python { .api }
102
def delete_lambda_function(self, function_name):
103
"""
104
Delete a Lambda function.
105
106
Parameters:
107
- function_name: str, name of the function to delete
108
109
Returns:
110
bool: True if deletion successful
111
"""
112
```
113
114
### Lambda Function Information
115
116
Retrieve Lambda function metadata, versions, and invocation capabilities.
117
118
```python { .api }
119
def get_lambda_function(self, function_name):
120
"""
121
Get Lambda function configuration.
122
123
Parameters:
124
- function_name: str, name of the function
125
126
Returns:
127
dict: Function configuration and metadata
128
"""
129
```
130
131
```python { .api }
132
def get_lambda_function_versions(self, function_name):
133
"""
134
Get all versions of a Lambda function.
135
136
Parameters:
137
- function_name: str, name of the function
138
139
Returns:
140
list: List of function versions
141
"""
142
```
143
144
```python { .api }
145
def invoke_lambda_function(
146
self,
147
function_name,
148
payload=None,
149
invocation_type='RequestResponse'
150
):
151
"""
152
Invoke a Lambda function.
153
154
Parameters:
155
- function_name: str, name of the function
156
- payload: dict, input data for the function
157
- invocation_type: str, 'RequestResponse' (sync) or 'Event' (async)
158
159
Returns:
160
dict: Function response and metadata
161
"""
162
```
163
164
### Version Management
165
166
Handle Lambda function versioning and rollback operations.
167
168
```python { .api }
169
def rollback_lambda_function_version(
170
self,
171
function_name,
172
versions_back=1,
173
publish=True
174
):
175
"""
176
Roll back Lambda function to a previous version.
177
178
Parameters:
179
- function_name: str, name of the function
180
- versions_back: int, number of versions to roll back
181
- publish: bool, publish the rollback as a new version
182
183
Returns:
184
dict: Updated function configuration
185
"""
186
```
187
188
### API Gateway Management
189
190
Deploy and manage API Gateway configurations for Lambda functions.
191
192
```python { .api }
193
def deploy_api_gateway(
194
self,
195
api_id,
196
stage_name='dev',
197
stage_description=None,
198
cache_cluster_enabled=False,
199
cache_cluster_size=None,
200
variables=None,
201
description=None,
202
**kwargs
203
):
204
"""
205
Deploy API Gateway stage.
206
207
Parameters:
208
- api_id: str, API Gateway REST API ID
209
- stage_name: str, name of the deployment stage
210
- stage_description: str, description of the stage
211
- cache_cluster_enabled: bool, enable caching
212
- cache_cluster_size: str, cache cluster size
213
- variables: dict, stage variables
214
- description: str, deployment description
215
216
Returns:
217
dict: Deployment configuration
218
"""
219
```
220
221
```python { .api }
222
def undeploy_api_gateway(self, api_id, stage_name=None):
223
"""
224
Remove API Gateway deployment.
225
226
Parameters:
227
- api_id: str, API Gateway REST API ID
228
- stage_name: str, stage to undeploy (optional)
229
230
Returns:
231
bool: True if removal successful
232
"""
233
```
234
235
```python { .api }
236
def create_api_gateway_routes(
237
self,
238
lambda_arn,
239
api_id=None,
240
resource_id=None,
241
**kwargs
242
):
243
"""
244
Create API Gateway routes for Lambda function.
245
246
Parameters:
247
- lambda_arn: str, ARN of the Lambda function
248
- api_id: str, API Gateway REST API ID
249
- resource_id: str, API Gateway resource ID
250
251
Returns:
252
dict: Route configuration
253
"""
254
```
255
256
### Package Management
257
258
Create and manage deployment packages for Lambda functions.
259
260
```python { .api }
261
def create_lambda_zip(
262
self,
263
prefix='lambda_package',
264
handler_file=None,
265
use_precompiled_packages=True,
266
exclude=None,
267
**kwargs
268
):
269
"""
270
Create deployment ZIP package for Lambda.
271
272
Parameters:
273
- prefix: str, prefix for the ZIP filename
274
- handler_file: str, path to the handler file
275
- use_precompiled_packages: bool, use precompiled packages
276
- exclude: list, files/patterns to exclude
277
278
Returns:
279
str: Path to created ZIP file
280
"""
281
```
282
283
### S3 Upload Operations
284
285
Upload deployment packages and other files to S3 buckets.
286
287
```python { .api }
288
def upload_to_s3(
289
self,
290
file_path,
291
bucket_name,
292
key_name=None,
293
disable_progress=False
294
):
295
"""
296
Upload file to S3 bucket.
297
298
Parameters:
299
- file_path: str, local path to file
300
- bucket_name: str, S3 bucket name
301
- key_name: str, S3 object key (optional)
302
- disable_progress: bool, disable progress display
303
304
Returns:
305
str: S3 URL of uploaded file
306
"""
307
```
308
309
### IAM Role Management
310
311
Create and manage IAM roles for Lambda function execution.
312
313
```python { .api }
314
def create_iam_roles(self):
315
"""
316
Create IAM roles and policies for Lambda execution.
317
318
Creates execution role with basic Lambda permissions
319
and attaches necessary policies for AWS service access.
320
321
Returns:
322
str: IAM role ARN
323
"""
324
```
325
326
```python { .api }
327
def get_credentials_arn(self):
328
"""
329
Get IAM role ARN for Lambda execution.
330
331
Retrieves the ARN of the IAM role used for Lambda
332
function execution and AWS service access.
333
334
Returns:
335
str: IAM role ARN
336
"""
337
```
338
339
### Event Scheduling
340
341
Manage CloudWatch Events for scheduled Lambda execution.
342
343
```python { .api }
344
def schedule_events(self, lambda_arn, lambda_name, events):
345
"""
346
Schedule CloudWatch Events for Lambda function.
347
348
Creates CloudWatch Event rules with cron or rate expressions
349
to trigger Lambda function execution on schedule.
350
351
Parameters:
352
- lambda_arn: str, Lambda function ARN
353
- lambda_name: str, Lambda function name
354
- events: list, event configuration with schedules
355
356
Returns:
357
dict: Event rule configuration
358
"""
359
```
360
361
```python { .api }
362
def unschedule_events(self, events, lambda_name):
363
"""
364
Remove scheduled events for Lambda function.
365
366
Deletes CloudWatch Event rules and removes
367
Lambda function triggers for scheduled execution.
368
369
Parameters:
370
- events: list, event configurations to remove
371
- lambda_name: str, Lambda function name
372
373
Returns:
374
bool: True if removal successful
375
"""
376
```
377
378
### Application Load Balancer Integration
379
380
Deploy Lambda functions with Application Load Balancer integration.
381
382
```python { .api }
383
def deploy_lambda_alb(self, **kwargs):
384
"""
385
Deploy Lambda function with ALB integration.
386
387
Creates Application Load Balancer infrastructure and
388
configures Lambda function as target for ALB requests.
389
390
Parameters:
391
- **kwargs: ALB configuration options
392
393
Returns:
394
dict: ALB deployment configuration
395
"""
396
```
397
398
```python { .api }
399
def undeploy_lambda_alb(self, **kwargs):
400
"""
401
Remove ALB integration for Lambda function.
402
403
Removes Application Load Balancer infrastructure
404
and cleans up ALB-related resources.
405
406
Parameters:
407
- **kwargs: ALB configuration options
408
409
Returns:
410
bool: True if removal successful
411
"""
412
```
413
414
### Domain Management
415
416
Manage custom domains and SSL certificates for API Gateway.
417
418
```python { .api }
419
def create_domain_name(self, domain, certificate_arn, **kwargs):
420
"""
421
Create custom domain for API Gateway.
422
423
Sets up custom domain with SSL certificate
424
for API Gateway REST API endpoints.
425
426
Parameters:
427
- domain: str, custom domain name
428
- certificate_arn: str, SSL certificate ARN
429
- **kwargs: Domain configuration options
430
431
Returns:
432
dict: Domain configuration
433
"""
434
```
435
436
```python { .api }
437
def update_domain_name(self, domain, certificate_arn):
438
"""
439
Update SSL certificate for custom domain.
440
441
Updates existing custom domain with new
442
SSL certificate for certificate renewal.
443
444
Parameters:
445
- domain: str, custom domain name
446
- certificate_arn: str, new SSL certificate ARN
447
448
Returns:
449
dict: Updated domain configuration
450
"""
451
```
452
453
```python { .api }
454
def get_domain_name(self, domain):
455
"""
456
Get custom domain configuration and status.
457
458
Retrieves configuration and status information
459
for existing custom domain setup.
460
461
Parameters:
462
- domain: str, custom domain name
463
464
Returns:
465
dict: Domain configuration and status
466
"""
467
```
468
469
### CloudFormation Integration
470
471
Generate and manage CloudFormation stacks for infrastructure.
472
473
```python { .api }
474
def create_stack_template(self, **kwargs):
475
"""
476
Generate CloudFormation template for deployment.
477
478
Creates CloudFormation template with Lambda function,
479
API Gateway, IAM roles, and other necessary resources.
480
481
Parameters:
482
- **kwargs: Stack template configuration
483
484
Returns:
485
dict: CloudFormation template
486
"""
487
```
488
489
```python { .api }
490
def update_stack(self, stack_name, template, **kwargs):
491
"""
492
Update existing CloudFormation stack.
493
494
Updates CloudFormation stack with new template
495
and configuration changes.
496
497
Parameters:
498
- stack_name: str, CloudFormation stack name
499
- template: dict, CloudFormation template
500
- **kwargs: Update configuration
501
502
Returns:
503
dict: Stack update response
504
"""
505
```
506
507
```python { .api }
508
def delete_stack(self, stack_name):
509
"""
510
Delete CloudFormation stack and resources.
511
512
Removes CloudFormation stack and all associated
513
AWS resources.
514
515
Parameters:
516
- stack_name: str, CloudFormation stack name
517
518
Returns:
519
bool: True if deletion initiated successfully
520
"""
521
```
522
523
### API Gateway Advanced Configuration
524
525
Advanced API Gateway configuration and management.
526
527
```python { .api }
528
def add_binary_support(self, api_id, cors_config=None):
529
"""
530
Enable binary content support for API Gateway.
531
532
Configures API Gateway to handle binary content types
533
like images, PDFs, and other non-text responses.
534
535
Parameters:
536
- api_id: str, API Gateway REST API ID
537
- cors_config: dict, CORS configuration (optional)
538
539
Returns:
540
dict: Binary support configuration
541
"""
542
```
543
544
```python { .api }
545
def remove_binary_support(self, api_id):
546
"""
547
Disable binary content support for API Gateway.
548
549
Removes binary content type handling from
550
API Gateway configuration.
551
552
Parameters:
553
- api_id: str, API Gateway REST API ID
554
555
Returns:
556
bool: True if removal successful
557
"""
558
```
559
560
```python { .api }
561
def add_api_compression(self, api_id):
562
"""
563
Enable response compression for API Gateway.
564
565
Configures API Gateway to compress responses
566
for improved performance and reduced bandwidth.
567
568
Parameters:
569
- api_id: str, API Gateway REST API ID
570
571
Returns:
572
dict: Compression configuration
573
"""
574
```
575
576
### Async Task Infrastructure
577
578
Create infrastructure for asynchronous task processing.
579
580
```python { .api }
581
def create_async_sns_topic(self, lambda_name):
582
"""
583
Create SNS topic for async task processing.
584
585
Sets up SNS topic and subscriptions for
586
asynchronous Lambda task execution.
587
588
Parameters:
589
- lambda_name: str, Lambda function name
590
591
Returns:
592
str: SNS topic ARN
593
"""
594
```
595
596
```python { .api }
597
def create_async_dynamodb_table(self, lambda_name):
598
"""
599
Create DynamoDB table for async task responses.
600
601
Sets up DynamoDB table to store responses from
602
asynchronous Lambda task executions.
603
604
Parameters:
605
- lambda_name: str, Lambda function name
606
607
Returns:
608
str: DynamoDB table name
609
"""
610
```
611
612
## Constants
613
614
```python { .api }
615
# AWS regions
616
API_GATEWAY_REGIONS = [
617
'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2',
618
'eu-west-1', 'eu-west-2', 'eu-central-1',
619
'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1'
620
]
621
622
LAMBDA_REGIONS = [
623
'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2',
624
'eu-west-1', 'eu-west-2', 'eu-central-1',
625
'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1'
626
]
627
628
# Architecture constants
629
X86_ARCHITECTURE = 'x86_64'
630
ARM_ARCHITECTURE = 'arm64'
631
VALID_ARCHITECTURES = ('x86_64', 'arm64')
632
633
# Default exclusions for ZIP packages
634
ZIP_EXCLUDES = [
635
"*.exe",
636
"*.DS_Store",
637
"*.Python",
638
"*.git",
639
".git/*",
640
"*.zip",
641
"*.tar.gz",
642
"*.hg",
643
"pip",
644
"docutils*",
645
"setuputils*",
646
"__pycache__/*"
647
]
648
649
# IAM policy templates
650
ASSUME_POLICY = """{
651
"Version": "2012-10-17",
652
"Statement": [
653
{
654
"Sid": "",
655
"Effect": "Allow",
656
"Principal": {
657
"Service": [
658
"apigateway.amazonaws.com",
659
"lambda.amazonaws.com",
660
"events.amazonaws.com"
661
]
662
},
663
"Action": "sts:AssumeRole"
664
}
665
]
666
}"""
667
668
ATTACH_POLICY = """{
669
"Version": "2012-10-17",
670
"Statement": [
671
{
672
"Effect": "Allow",
673
"Action": [
674
"logs:*"
675
],
676
"Resource": "arn:aws:logs:*:*:*"
677
},
678
{
679
"Effect": "Allow",
680
"Action": [
681
"lambda:InvokeFunction"
682
],
683
"Resource": [
684
"*"
685
]
686
}
687
]
688
}"""
689
```