This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.html
1315 lines (897 loc) · 47.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Apex – Serverless Infrastructure</title>
<meta name="keywords" content="apex, serverless, lambda, aws, aws lambda, functions, golang, go">
<meta name="description" content="Apex serverless infrastructure built on AWS Lambda">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="public/style.css" media="screen" charset="utf-8">
<link rel="stylesheet" href="public/syntax.css" media="screen" charset="utf-8">
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
analytics.load("tA9zrxd7Eh20dfKQ15h5nt8LolDapYVg");
analytics.page()
}}();
</script>
</head>
<body>
<header>
<div id="header-overlay"></div>
<span id="logo"></span>
<div id="menu">
<i class="material-icons">menu</i>
<ul id="menu-items">
<li><a href="#installation">Installation</a></li>
<li><a href="#aws-credentials">AWS credentials</a></li>
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#autocomplete">Autocomplete</a></li>
<li><a href="#structuring-projects">Structuring projects</a></li>
<li><a href="#structuring-functions">Structuring functions</a></li>
<li><a href="#deploying-functions">Deploying functions</a></li>
<li><a href="#invoking-functions">Invoking functions</a></li>
<li><a href="#listing-functions">Listing functions</a></li>
<li><a href="#deleting-functions">Deleting functions</a></li>
<li><a href="#building-functions">Building functions</a></li>
<li><a href="#rolling-back-versions">Rolling back versions</a></li>
<li><a href="#aliasing-versions">Aliasing versions</a></li>
<li><a href="#function-hooks">Function hooks</a></li>
<li><a href="#viewing-log-output">Viewing log output</a></li>
<li><a href="#viewing-metrics">Viewing metrics</a></li>
<li><a href="#managing-infrastructure">Managing infrastructure</a></li>
<li><a href="#previewing-with-dry-run">Previewing with dry-run</a></li>
<li><a href="#environment-variables">Environment variables</a></li>
<li><a href="#omitting-files">Omitting files</a></li>
<li><a href="#understanding-the-shim">Understanding the shim</a></li>
<li><a href="#viewing-documentation">Viewing documentation</a></li>
<li><a href="#upgrading-apex">Upgrading Apex</a></li>
<li><a href="#faq">FAQ</a></li>
<li><a href="#links">Links</a></li>
<li><a href="https://github.com/apex/apex/tree/master/_examples">Examples</a></li>
<li><a href="https://github.com/apex/apex">GitHub</a></li>
<li><a href="https://twitter.com/tjholowaychuk">Twitter</a></li>
<li><a href="https://medium.com/@tjholowaychuk">Medium</a></li>
</ul>
</div>
<span id="more">
<i class="material-icons">expand_more</i>
</span>
</header>
<section id="content">
<p>
Apex lets you build, deploy, and manage AWS Lambda functions with ease. With Apex you can use
languages that are not natively supported by AWS Lambda, such as Golang, through the use
of a Node.js shim injected into the build. A variety of workflow related tooling is provided for
testing functions, rolling back deploys, viewing metrics, tailing
logs, hooking into the build system and more.
</p>
<article>
<h1 id="installation">Installation</h1>
<p>On macOS, Linux, or OpenBSD run the following:</p>
<pre><code>curl https://raw.githubusercontent.com/apex/apex/master/install.sh | sh
</code></pre>
<p>This command will install <code>apex</code> binary as <code>/usr/local/bin/apex</code> and
you may need to run the <code>sudo</code> version below, or alternatively chown <code>/usr/local</code>:</p>
<pre><code>curl https://raw.githubusercontent.com/apex/apex/master/install.sh | sudo sh
</code></pre>
<p>You can specify a destination as below</p>
<pre><code>curl https://raw.githubusercontent.com/apex/apex/master/install.sh | DEST=$HOME/bin/apex sh
</code></pre>
<p>this command will install <code>apex</code> binary as <code>$HOME/bin/apex</code> and you may not need to use <code>sudo</code>.</p>
<p>On Windows download <a href="https://github.com/apex/apex/releases">binary</a>.</p>
<p>If already installed, upgrade with:</p>
<pre><code>apex upgrade
</code></pre>
</article>
<article>
<h1 id="aws-credentials">AWS credentials</h1>
<p>Before using Apex you need to first give it your account credentials so that Apex can manage resources. There are a number of ways to do that, which are outlined here.</p>
<h2 id="via-environment-variables">Via environment variables</h2>
<p>Using environment variables only, you must specify the following:</p>
<ul>
<li><code>AWS_ACCESS_KEY_ID</code> AWS account access key</li>
<li><code>AWS_SECRET_ACCESS_KEY</code> AWS account secret key</li>
<li><code>AWS_REGION</code> AWS region</li>
</ul>
<p>If you have multiple AWS projects you may want to consider using a tool such as <a href="https://direnv.net/">direnv</a> to localize and automatically set the variables when
you’re working on a project.</p>
<h2 id="via-aws-files">Via ~/.aws files</h2>
<p>Using the ~/.aws/credentials and ~/.aws/config files you may specify <code>AWS_PROFILE</code> to tell apex which one to reference. However, if you do not have a ~/.aws/config file, or “region” is not defined, you should set it with the <code>AWS_REGION</code> environment variable. To read more on configuring these files view <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html">Configuring the AWS CLI</a>.</p>
<p>Here’s an example of ~/.aws/credentials:</p>
<pre><code>[example]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxx
</code></pre>
<p>Here’s an example of ~/.aws/config:</p>
<pre><code>[profile example]
output = json
region = us-west-2
</code></pre>
<h2 id="via-profile-flag">Via profile flag</h2>
<p>If you have both ~/.aws/credentials and ~/.aws/config you may specify the profile directly with <code>apex --profile <name></code> when issuing commands. This means you do not have to specify any environment variables, however you must provide it with each operation:</p>
<pre><code>$ apex --profile myapp-prod deploy
</code></pre>
<h2 id="via-project-configuration">Via project configuration</h2>
<p>You may store the profile name in the project.json file itself as shown in the following snippet. This is ideal since it ensures that you do not accidentally have a different environment set.</p>
<pre><code class="language-json">{
"profile": "myapp-prod"
}
</code></pre>
<h2 id="via-iam-role">Via IAM Role</h2>
<p>Using an IAM role can be achieved in two ways, via the <strong>AWS_ROLE</strong> environment variable or via a command line flag <code>--iamrole</code>. As with other Apex credential loading, the command line flag will supersede the environment variable.</p>
<h2 id="precedence">Precedence</h2>
<p>Precedence for loading the AWS credentials is:</p>
<ul>
<li>profile from flag</li>
<li>profile from JSON config</li>
<li>profile from env variables</li>
<li>profile named “default”</li>
</ul>
<h2 id="minimum-iam-policy">Minimum IAM Policy</h2>
<p>Below is a policy for AWS <a href="https://aws.amazon.com/iam/">Identity and Access Management</a> which provides the minimum privileges needed to use Apex to manage your Lambda functions.</p>
<pre><code class="language-json">{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"iam:CreateRole",
"iam:CreatePolicy",
"iam:AttachRolePolicy",
"iam:PassRole",
"lambda:GetFunction",
"lambda:ListFunctions",
"lambda:CreateFunction",
"lambda:DeleteFunction",
"lambda:InvokeFunction",
"lambda:GetFunctionConfiguration",
"lambda:UpdateFunctionConfiguration",
"lambda:UpdateFunctionCode",
"lambda:CreateAlias",
"lambda:UpdateAlias",
"lambda:GetAlias",
"lambda:ListAliases",
"lambda:ListVersionsByFunction",
"logs:FilterLogEvents",
"cloudwatch:GetMetricStatistics"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
</code></pre>
<h3 id="additional-minimum-iam-policy-to-set-vpc-for-lambda">Additional minimum IAM Policy to set VPC for Lambda</h3>
<p>The following additional policies are needed to set VPC for your Lambda functions.</p>
<pre><code class="language-json">{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
</code></pre>
<p>Also, the role which apex made during <code>apex init</code> should have the <code>AWSLambdaVPCAccessExecutionRole</code> policy, see details in <a href="https://docs.aws.amazon.com/lambda/latest/dg/vpc.html">an AWS document</a>.</p>
</article>
<article>
<h1 id="getting-started">Getting started</h1>
<p>Apex can help initialize a basic project to get you started. First specify your AWS credentials as mentioned in the previous section, then run <code>apex init</code>:</p>
<pre><code>$ export AWS_PROFILE=sloths-stage
$ apex init
</code></pre>
<p>You’ll be presented with a few prompts, the project’s default Lambda IAM role & policy will be created, then you’re ready to go!</p>
<pre><code> _ ____ _______ __
/ \ | _ \| ____\ \/ /
/ _ \ | |_) | _| \ /
/ ___ \| __/| |___ / \
/_/ \_\_| |_____/_/\_\
Enter the name of your project. It should be machine-friendly, as this
is used to prefix your functions in Lambda.
Project name: sloths
Enter an optional description of your project.
Project description: My slothy project
[+] creating IAM sloth_lambda_function role
[+] creating IAM sloth_lambda_logs policy
[+] attaching policy to lambda_function role.
[+] creating ./project.json
[+] creating ./functions
Setup complete, deploy those functions!
$ apex deploy
</code></pre>
<p>Now try invoking the sample function:</p>
<pre><code>$ apex invoke hello
{"hello":"world"}
</code></pre>
</article>
<article>
<h1 id="autocomplete">Autocomplete</h1>
<p>Apex supports command and function name autocompletion. To enable this functionality you’ll need to add the following shell script to your profile or similar:</p>
<pre><code class="language-sh">_apex() {
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local opts="$(apex autocomplete -- ${COMP_WORDS[@]:1})"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _apex apex
</code></pre>
</article>
<article>
<h1 id="structuring-projects">Structuring projects</h1>
<p>A “project” is the largest unit of abstraction in Apex. A project consists of collection of AWS Lambda functions, and
all <code>apex(1)</code> operations have access to these functions.</p>
<h2 id="configuration">Configuration</h2>
<p>Projects have a project.json file in the root directory. This file contains details about your project, as well as
defaults for functions, if desired. Here’s an example of a project.json file declaring a default AWS IAM “role” and “memory” for all functions.</p>
<pre><code class="language-json">{
"name": "node",
"description": "Node.js example project",
"role": "arn:aws:iam::293503197324:role/lambda",
"memory": 512
}
</code></pre>
<h2 id="multiple-environments">Multiple Environments</h2>
<p>Multiple environments are supported with the <code>--env</code> flag. By default project.json and function.json are used, however when <code>--env</code> is specified project.ENV.json and function.ENV.json will be used, falling back on function.json for cases when staging and production config is the same. For example your directory structure may look something like the following:</p>
<pre><code>project.stage.json
project.prod.json
functions
├── bar
│ ├── function.stage.json
│ ├── function.prod.json
│ └── index.js
└── foo
├── function.stage.json
├── function.prod.json
└── index.js
</code></pre>
<p>If you prefer your “dev” or “staging” environment to be the implied default then leave the files as project.json and function.json:</p>
<pre><code>project.json
project.prod.json
functions
├── bar
│ ├── function.json
│ ├── function.prod.json
│ └── index.js
└── foo
├── function.json
├── function.prod.json
└── index.js
</code></pre>
<h2 id="symlinks">Symlinks</h2>
<p>It’s important to note that Apex supports symlinked files and directories. Apex will read the links and pull in these files, even if the links aren’t to files within your function. This enables the use of <code>npm link</code>, shared configuration and so on.</p>
<h2 id="fields">Fields</h2>
<h3 id="name">name</h3>
<p>Name of the project. This field is used in the default value for “nameTemplate” to prevent collisions between multiple projects.</p>
<ul>
<li>type: <code>string</code></li>
<li>required</li>
</ul>
<h3 id="description">description</h3>
<p>Description of the project. This field is informational.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="runtime">runtime</h3>
<p>Default runtime of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<p>Runtimes supported:</p>
<ul>
<li><strong>java</strong> (Java 8)</li>
<li><strong>python2.7</strong> (Python 2.7)</li>
<li><strong>python3.6</strong> (Python 3.6)</li>
<li><strong>nodejs4.3</strong> (Node.js 4.3)</li>
<li><strong>nodejs4.3-edge</strong> (Node.js 4.3 Edge)</li>
<li><strong>nodejs6.10</strong> (Node.js 6.10)</li>
<li><strong>golang</strong> (any version)</li>
<li><strong>clojure</strong> (any version)</li>
<li><strong>rust-musl[^rust-runtime][^rust-linux-only]</strong> (any version)</li>
<li><strong>rust-gnu[^rust-runtime][^rust-linux-only]</strong> (any version)</li>
</ul>
<p>[^rust-runtime]: Rust has two types of libc dependencies and the <strong>rust-musl</strong> is recommended. Your rust lambda function may refuse to run because of glibc version mismatch between lambda server and your pc when <strong>rust-gnu</strong> runtime is used.</p>
<p>[^rust-linux-only]: Rust version of lambda currently can only be built on linux machine. If you try to build on MacOS, you will encounter the linker error. One solution is using apex inside a linux docker container on MacOS.</p>
<h3 id="memory">memory</h3>
<p>Default memory allocation of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>int</code></li>
</ul>
<h3 id="timeout">timeout</h3>
<p>Default timeout of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>int</code></li>
</ul>
<h3 id="role">role</h3>
<p>Default role of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="profile">profile</h3>
<p>Name of the AWS profile to use, this is the name used to locate AWS credentials in ~/.aws/credentials. Use this if you’d prefer not to specify <code>AWS_PROFILE</code> or <code>--profile</code>.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="region">region</h3>
<p>Name of the AWS region to use. Use this if you’d prefer not to specify <code>AWS_REGION</code> or <code>--region</code>.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="defaultenvironment">defaultEnvironment</h3>
<p>Default infrastructure environment.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="environment">environment</h3>
<p>Default environment variables of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>object</code></li>
</ul>
<h3 id="nametemplate">nameTemplate</h3>
<p>Template used to compute the function names. By default the template <code>{{.Project.Name}}_{{.Function.Name}}</code> is used, for example project “api” and <code>./functions/users</code> becomes “api_users”. To disable prefixing, use <code>{{.Function.Name}}</code>, which would result in “users”.</p>
<ul>
<li>type: <code>string</code></li>
</ul>
<h3 id="retainedversions">retainedVersions</h3>
<p>Default number of retained function’s versions on AWS Lambda unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>int</code></li>
</ul>
<h3 id="vpc">vpc</h3>
<p>Default VPC configuration of function(s) unless specified in their function.json configuration.</p>
<ul>
<li>type: <code>object</code></li>
</ul>
<h4 id="vpc-securitygroups">vpc.securityGroups</h4>
<p>List of security groups IDs</p>
<ul>
<li>type: <code>array</code></li>
</ul>
<h4 id="vpc-subnets">vpc.subnets</h4>
<p>List of subnets IDs</p>
<ul>
<li>type: <code>array</code></li>
</ul>
</article>
<article>
<h1 id="structuring-functions">Structuring functions</h1>
<p>A function is the smallest unit in Apex. A function represents an AWS Lambda function.</p>
<p>Functions must include at least one source file (runtime dependent), such as index.js or main.go. Optionally a function.json file may be placed in the <em>function’s directory</em>, specifying details such as the memory allocated or the AWS IAM role. If one or more functions is missing a function.json file you must provide defaults for the required fields in project.json (see “Projects” for an example).</p>
<h2 id="configuration">Configuration</h2>
<pre><code class="language-json">{
"description": "Node.js example function",
"runtime": "nodejs",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda"
}
</code></pre>
<h2 id="fields">Fields</h2>
<p>Fields marked as <code>inherited</code> may be provided in the project.json file instead.</p>
<h3 id="description">description</h3>
<p>Description of the function. This is used as the description in AWS Lambda.</p>
<ul>
<li>type: <code>string</code></li>
<li>required</li>
</ul>
<h3 id="runtime">runtime</h3>
<p>Runtime of the function. This is used as the runtime in AWS Lambda, or when required, is used to determine that the Node.js shim should be used. For example when this field is “golang”, the canonical runtime used is “nodejs” and a shim is injected into the zip file.</p>
<ul>
<li>type: <code>string</code></li>
<li>required</li>
<li>inherited</li>
</ul>
<h3 id="handler">handler</h3>
<p>Event handler name, this is the function invoked for a given event. Defaults are:</p>
<ul>
<li>nodejs: <code>index.handle</code> (index.js file with <code>handle</code> exported function)</li>
<li>python: <code>handle</code></li>
<li>java: <code>lambda.Main::handler</code></li>
</ul>
<h3 id="memory">memory</h3>
<p>Memory allocated to the function, in megabytes.</p>
<ul>
<li>type: <code>int</code></li>
<li>required</li>
<li>inherited</li>
</ul>
<h3 id="timeout">timeout</h3>
<p>Function timeout in seconds. Note that Lambda currently restricts durations to 5 minutes (300s).</p>
<ul>
<li>type: <code>int</code></li>
<li>required</li>
<li>inherited</li>
</ul>
<h3 id="role">role</h3>
<p>AWS Lambda role used.</p>
<ul>
<li>type: <code>string</code></li>
<li>required</li>
<li>inherited</li>
</ul>
<h3 id="environment">environment</h3>
<p>Environment variables.</p>
<ul>
<li>type: <code>object</code></li>
<li>inherited</li>
</ul>
<h3 id="retainedversions">retainedVersions</h3>
<p>Number of retained function’s versions on AWS Lambda. If not specified <code>deploy</code> command will leave 10 versions.</p>
<ul>
<li>type: <code>int</code></li>
<li>inherited</li>
</ul>
<h3 id="vpc">vpc</h3>
<p>If your function needs to access resources in a VPC security groups and subnets have to be provided. You must provide at least one security group and one subnet.</p>
<ul>
<li>type: <code>object</code></li>
<li>inherited</li>
</ul>
<h4 id="vpc-securitygroups">vpc.securityGroups</h4>
<p>List of security groups IDs</p>
<ul>
<li>type: <code>array</code></li>
<li>inherited</li>
</ul>
<h4 id="vpc-subnets">vpc.subnets</h4>
<p>List of subnets IDs</p>
<ul>
<li>type: <code>array</code></li>
<li>inherited</li>
</ul>
<h3 id="kms-arn">kms_arn</h3>
<p>Optional ARN of the KMS key used to encrypt your function’s environment variables. If empty, it means you are using the AWS Lambda default service key.</p>
<h3 id="deadletter-arn">deadletter_arn</h3>
<p>Optional ARN of an Amazon SQS queue or Amazon SNS topic you specify as your Dead Letter Queue (DLQ).</p>
</article>
<article>
<h1 id="deploying-functions">Deploying functions</h1>
<p>To deploy one or more functions all you need to do is run <code>apex deploy</code>. Apex deploys are idempotent; a build is created
for each function, and Apex performs a checksum to see if the deployed function matches the local build, if so
it’s not deployed.</p>
<p>After deploy Apex will cleanup old function’s versions stored on AWS Lambda leaving only few. Number of retained versions
can be specified in project or function configuration.</p>
<p>If you prefer to be explicit you can pass one or more function names to <code>apex deploy</code>. You may also perform shell-style globbing matches with any command accepting function names, such as <code>deploy</code>, <code>logs</code>, and <code>rollback</code>.</p>
<h2 id="examples">Examples</h2>
<p>Deploy all functions in the current directory:</p>
<pre><code class="language-sh">$ apex deploy
</code></pre>
<p>Deploy all functions in the directory “~/dev/myapp”:</p>
<pre><code class="language-sh">$ apex deploy -C ~/dev/myapp
</code></pre>
<p>Deploy specific functions:</p>
<pre><code class="language-sh">$ apex deploy auth
$ apex deploy auth api
</code></pre>
<p>Deploy all functions which name starts with “auth”:</p>
<pre><code class="language-sh">$ apex deploy auth*
</code></pre>
<p>Deploy all functions ending with “_reporter”.</p>
<pre><code class="language-sh">$ apex deploy *_reporter
</code></pre>
<p>Deploy an existing zip file.</p>
<pre><code class="language-sh">$ apex build auth > /tmp/auth.zip
$ apex deploy auth --zip /tmp/auth.zip
</code></pre>
<p>Deploy with an alias. The alias is added regardless of changes to the function and its config.</p>
<pre><code class="language-sh">$ apex deploy --alias prod api
</code></pre>
</article>
<article>
<h1 id="invoking-functions">Invoking functions</h1>
<p>Apex allows you to invoke functions from the command-line, optionally passing a JSON event or stream to STDIN. It’s important to note that <code>invoke</code> will execute the remote Lambda function and not locally execute your function. It will execute the $LATEST Lambda function available.</p>
<h2 id="examples">Examples</h2>
<p>Invoke without an event:</p>
<pre><code class="language-sh">$ apex invoke collect-stats
</code></pre>
<p>Invoke with JSON event:</p>
<pre><code class="language-sh">$ echo -n '{ "value": "Tobi the ferret" }' | apex invoke uppercase
{ "value": "TOBI THE FERRET" }
</code></pre>
<p>Invoke from a file:</p>
<pre><code class="language-sh">$ apex invoke uppercase < event.json
</code></pre>
<p>Invoke a with stdin clipboard data:</p>
<pre><code class="language-sh">$ pbpaste | apex invoke auth
</code></pre>
<p>Invoke function in a different project:</p>
<pre><code class="language-sh">$ pbpaste | apex -C path/to/project invoke auth
</code></pre>
<p>Streaming invokes making multiple requests, generating data with <a href="https://github.com/yields/phony">phony</a>:</p>
<pre><code class="language-sh">$ echo -n '{ "user": "{{name}}" }' | phony | apex invoke uppercase
{"user":"DELMER MALONE"}
{"user":"JC REEVES"}
{"user":"LUNA FLETCHER"}
...
</code></pre>
<p>Streaming invokes making multiple requests and outputting the response logs:</p>
<pre><code class="language-sh">$ echo -n '{ "user": "{{name}}" }' | phony | apex invoke uppercase --logs
START RequestId: 30e826a4-a6b5-11e5-9257-c1543e9b73ac Version: $LATEST
END RequestId: 30e826a4-a6b5-11e5-9257-c1543e9b73ac
REPORT RequestId: 30e826a4-a6b5-11e5-9257-c1543e9b73ac Duration: 0.73 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 10 MB
{"user":"COLTON RHODES"}
START RequestId: 30f0b23c-a6b5-11e5-a034-ad63d48ca53a Version: $LATEST
END RequestId: 30f0b23c-a6b5-11e5-a034-ad63d48ca53a
REPORT RequestId: 30f0b23c-a6b5-11e5-a034-ad63d48ca53a Duration: 2.56 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 9 MB
{"user":"CAROLA BECK"}
START RequestId: 30f51e67-a6b5-11e5-8929-f53378ef0f47 Version: $LATEST
END RequestId: 30f51e67-a6b5-11e5-8929-f53378ef0f47
REPORT RequestId: 30f51e67-a6b5-11e5-8929-f53378ef0f47 Duration: 0.22 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 9 MB
{"user":"TOBI FERRET"}
...
</code></pre>
</article>
<article>
<h1 id="listing-functions">Listing functions</h1>
<p>Apex supports listing of functions in various outputs, currently human-friendly terminal output and “tfvars” support for integration with Terraform.</p>
<h2 id="examples">Examples</h2>
<p>List all functions and their configuration:</p>
<pre><code class="language-sh">$ apex list
bar
runtime: nodejs
memory: 128mb
timeout: 5s
role: arn:aws:iam::293503197324:role/lambda
handler: index.handle
aliases: current@v3, foo@v4
foo
runtime: nodejs
memory: 512mb
timeout: 10s
role: arn:aws:iam::293503197324:role/lambda
handler: index.handle
aliases: current@v12
</code></pre>
<p>Terraform vars output:</p>
<pre><code class="language-sh">$ apex list --tfvars
apex_function_bar="arn:aws:lambda:us-west-2:293503197324:function:testing_bar"
apex_function_foo="arn:aws:lambda:us-west-2:293503197324:function:testing_foo"
</code></pre>
</article>
<article>
<h1 id="deleting-functions">Deleting functions</h1>
<p>Apex allows you to delete functions, however it will prompt by default. Use the <code>-f, --force</code> flag to override this behaviour. You may pass zero or more function names.</p>
<h2 id="examples">Examples</h2>
<p>Delete all with prompt:</p>
<pre><code class="language-sh">$ apex delete
The following will be deleted:
- bar
- foo
Are you sure? (yes/no):
</code></pre>
<p>Force delete of all functions:</p>
<pre><code class="language-sh">$ apex delete -f
</code></pre>
<p>Force delete of specific functions:</p>
<pre><code class="language-sh">$ apex delete -f foo bar
</code></pre>
<p>Delete all functions which name starts with “auth”:</p>
<pre><code class="language-sh">$ apex delete auth*
</code></pre>
</article>
<article>
<h1 id="building-functions">Building functions</h1>
<p>Apex generates a zip file for you upon deploy, however sometimes it can be useful to see exactly what’s included in this file for debugging purposes. The <code>apex build</code> command outputs the zip to STDOUT for this purpose.</p>
<h2 id="examples">Examples</h2>
<p>Output zip to out.zip:</p>
<pre><code class="language-sh">$ apex build foo > out.zip
</code></pre>
</article>
<article>
<h1 id="rolling-back-versions">Rolling back versions</h1>
<p>Apex allows you to roll back to the previous, or specified version of a function.</p>
<h2 id="examples">Examples</h2>
<p>Rollback to the previous release:</p>
<pre><code class="language-sh">$ apex rollback foo
</code></pre>
<p>Rollback to specific version:</p>
<pre><code class="language-sh">$ apex rollback foo 5
</code></pre>
<p>Preview rollback with <code>--dry-run</code>:</p>
<pre><code class="language-sh">$ apex rollback --dry-run lowercase
~ alias testing_lowercase
alias: current
version: 2
$ apex rollback --dry-run uppercase 1
~ alias testing_uppercase
version: 1
alias: current
</code></pre>
</article>
<article>
<h1 id="aliasing-versions">Aliasing versions</h1>
<p>The <code>alias</code> command allows you to alias one or more function versions to a given alias.</p>
<h2 id="examples">Examples</h2>
<p>Alias all functions as “prod”:</p>
<pre><code>$ apex alias prod
</code></pre>
<p>Alias all “api_*” functions to “prod”:</p>
<pre><code>$ apex alias prod api_*
</code></pre>
<p>Alias all functions of version 5 to “prod”:</p>
<pre><code>$ apex alias -v 5 prod
</code></pre>
<p>Alias specific function to “stage”:</p>
<pre><code>$ apex alias stage myfunction
</code></pre>
<p>Alias specific function’s version 10 to “stage”:</p>
<pre><code>$ apex alias -v 10 stage myfunction
</code></pre>
<p>Alias specific function’s alias “dev” to “stage” alias (promote dev to stage):</p>
<pre><code>$ apex alias stage dev myfunction
</code></pre>
</article>
<article>
<h1 id="function-hooks">Function hooks</h1>
<p>Apex supports the notion of hooks, which allow you to execute shell commands throughout a function’s lifecycle. For example you may use these hooks to run tests or linting before a deploy, or to transpile source code using Babel, CoffeeScript, or similar.</p>
<p>Hooks may be specified in project.json or function.json. Hooks are executed in the function’s directory, not the project’s directory. If a hook exits > 0 then Apex will halt and display the error.</p>
<p>Internally Apex uses these hooks to implement out-of-the-box support for Golang and other compiled languages.</p>
<h2 id="supported-hooks">Supported hooks</h2>
<ul>
<li><code>build</code> run before a function zip is built (use this to compile binaries or transform source)</li>
<li><code>deploy</code> run before a function is deployed (useful for testing, linting)</li>
<li><code>clean</code> run after a function is deployed (useful for cleaning up build artifacts)</li>
</ul>
<h2 id="examples">Examples</h2>
<p>Here’s the hooks used internally for Golang support.</p>
<pre><code class="language-json">{
"hooks": {
"build": "GOOS=linux GOARCH=amd64 go build -o main main.go",
"clean": "rm -f main"
}
}
</code></pre>
</article>
<article>
<h1 id="viewing-log-output">Viewing log output</h1>
<p>Apex is integrated with CloudWatch Logs to view the output of functions. By default the logs for all functions will be displayed, unless one or more function names are passed to <code>apex logs</code>. You may also specify the duration of time in which the history is displayed (defaults to 5 minutes), as well as following and filtering results.</p>
<h2 id="examples">Examples</h2>
<p>View all function logs within the last 5 minutes:</p>
<pre><code class="language-sh">$ apex logs
</code></pre>
<p>View logs for “uppercase” and “lowercase” functions:</p>
<pre><code class="language-sh">$ apex logs uppercase lowercase
</code></pre>
<p>Follow or tail the log output for all functions:</p>
<pre><code class="language-sh">$ apex logs -f
</code></pre>
<p>Follow a specific function:</p>
<pre><code class="language-sh">$ apex logs -f foo
</code></pre>
<p>Follow filtered by pattern “error”:</p>
<pre><code class="language-sh">$ apex logs -f foo --filter error
$ apex logs -f foo -F error
</code></pre>
<p>Output the last hour of logs:</p>
<pre><code class="language-sh">$ apex logs --since 1h
$ apex logs -s 1h
</code></pre>
<p>Log all functions which name starts with “auth”:</p>
<pre><code class="language-sh">$ apex logs auth*
</code></pre>
</article>
<article>
<h1 id="viewing-metrics">Viewing metrics</h1>
<p>The <code>apex metrics</code> command provides a quick glance at the overall metrics for your functions, displaying the number of invocations, total execution duration, throttling, and errors within a given time period.</p>
<h2 id="examples">Examples</h2>
<p>View all function metrics within the last 24 hours:</p>