Skip to content

Commit 2412e5c

Browse files
authored
Merge pull request #127 from dwyl/quick-tidy-2026-issue-#126
PR: Quick Tidy to Share #126
2 parents 05151c1 + 1febe48 commit 2412e5c

13 files changed

Lines changed: 12497 additions & 62 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: npm
4+
directory: "/"
5+
schedule:
6+
# Non-critical learning code, update deps infrequently.
7+
interval: monthly
8+
time: "17:00"
9+
timezone: Europe/London

‎.github/workflows/ci.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Node.js CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
node-version: [24.x]
15+
os: [ubuntu-latest, windows-latest, macos-latest]
16+
steps:
17+
- uses: actions/checkout@v7 # github.com/actions/checkout
18+
- uses: actions/setup-node@v7 # github.com/actions/setup-node
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- run: npm i
22+
- run: npm test
23+
- name: Upload coverage reports to Codecov
24+
uses: codecov/codecov-action@v7 # github.com/codecov/codecov-action
25+
with:
26+
token: ${{ secrets.CODECOV_TOKEN }}

‎README.md‎

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,83 @@
1+
<div align="center">
2+
13
# Learn Aws Lambda
24

35
![aws lambda intro image](https://i.imgur.com/9ImDKrv.jpg)
46

5-
Learn to use AWS Lambda to create scalable micro-services in less time
6-
and cost *far* less to run than "*traditional*" server-based apps.
7-
8-
[![Codeship](https://img.shields.io/codeship/dc9ad800-a8a7-0133-6c3b-2a9c037ce78e/master.svg?style=flat-square)](https://github.com/codeship/documentation/issues/335)
9-
[![codecov.io](https://codecov.io/github/dwyl/learn-aws-lambda/coverage.svg?branch=master)](https://codecov.io/github/dwyl/learn-aws-lambda?branch=master)
10-
[![dependencies Status](https://david-dm.org/dwyl/learn-aws-lambda/status.svg)](https://david-dm.org/dwyl/learn-aws-lambda)
11-
[![devDependencies Status](https://david-dm.org/dwyl/learn-aws-lambda/dev-status.svg)](https://david-dm.org/dwyl/learn-aws-lambda?type=dev)
12-
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/learn-aws-lambda/issues)
13-
7+
Learn to use `AWS Lambda`
8+
to create **scalable micro-services**<br />
9+
in less time
10+
and lower overhead
11+
than "*traditional*" server-based apps.
12+
13+
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/learn-aws-lambda/ci.yml?label=build&style=flat-square&branch=main)](https://github.com/dwyl/learn-aws-lambda/actions/workflows/ci.yml)
14+
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/learn-aws-lambda/main.svg?style=flat-square)](https://codecov.io/github/dwyl/hits?branch=main)
15+
[![HitCount](https://hits.dwyl.com/dwyl/learn-aws-lambda.svg)](https://github.com/dwyl/learn-aws-lambda)
16+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/learn-aws-lambda/issues/)
17+
</div>
18+
19+
# Disclaimer ⚠️
20+
21+
We wrote these notes from **2015 - 2021**
22+
to **_extensively_ capture** our **knowledge** of using `AWS Lambda`
23+
to build both simple functions
24+
(e.g: "send email" or "transform an image")
25+
and more advanced "serverless apps".
26+
All credit to
27+
[Nikhi](https://github.com/nikhilaravi)
28+
and
29+
[Jack](https://github.com/jackcarlisle)
30+
for their superb work,
31+
subsequently extended/improved by
32+
[other dwylers](https://github.com/dwyl/learn-aws-lambda/graphs/contributors?all=1).
33+
🫶
34+
35+
While the notes can still serve as a **reference**,
36+
they are **no longer current** with the **_latest_ `Lambda` UI**.
37+
38+
Most of the code examples will still work because they are reasonable simple.
39+
If you get stuck with any of them,
40+
please
41+
[open an issue](https://github.com/dwyl/learn-aws-lambda/issues).
42+
43+
We still have several functions running smoothly on `Lambda`
44+
with zero maintenance required (beyond updating Node.js version),
45+
both for our own internal apps and client apps,
46+
but we have not had time to update the notes. ⏳
47+
e.g:
48+
[dwyl/**aws-ses-lambda**](https://github.com/dwyl/aws-ses-lambda)
49+
and
50+
[`github-scraper/lambda`](https://github.com/nelsonic/github-scraper/tree/main/lambda)
51+
52+
We also built our own micro `Lambda` **deployment tool**:
53+
[dwyl/**aws-lambda-deploy**](https://github.com/dwyl/aws-lambda-deploy)
54+
which still works flawlessly 10+ years later!
55+
A testament to its simplicity and
56+
[ultra-low dependency count!](https://github.com/dwyl/aws-lambda-deploy/blob/5b5518696e28e77800994c48f2d3a3af75bd0e5d/package.json#L71-L74)
57+
58+
`AWS` recently released a new feature
59+
that allows directly calling a `Lambda` function
60+
via a URL without requiring the complexity of `API Gateway`:
61+
[dwyl/learn-aws-lambda#124](https://github.com/dwyl/learn-aws-lambda/issues/124).
62+
This **_significantly_ simplifies** invoking `Lambda`
63+
functions from other non-lambda apps.
64+
65+
If you're looking for a way to offload some processing to `Lambda`
66+
from your existing non-lambda app/backend,
67+
we recommend exploring this option.
68+
69+
We **do _not_ recommend** building an entire (complex)
70+
"[Serverless](https://github.com/dwyl/learn-aws-lambda/issues/119)"
71+
backend using `Lambda`
72+
because the request/response time is quite slow compared to a
73+
[**`Phoenix`**](https://github.com/dwyl/technology-stack)
74+
App
75+
and more tedious to test & deploy all the moving parts.
76+
But for simpler async functions it's great
77+
and there is a
78+
[_generous_ one million requests **free tier**](https://aws.amazon.com/lambda/pricing/).
79+
80+
Happy Coding! ❤️
1481

1582
## Contents
1683

@@ -210,7 +277,7 @@ by following one of the previous examples!)_
210277
211278
5. Now let's test our endpoint to see if our Lambda function is being invoked. Go to the AWS console and then click on 'API Gateway' under Application Services. This will take you to a list of your APIs where you should see the one we just created. Click on the title.
212279
213-
![api list](https://github.com/4thAce/learn-aws-lambda/blob/master/api-gateway-lambda-microservice.png?raw=true)
280+
![api list](https://github.com/user-attachments/assets/cc0d85b7-d5b7-45b8-af5a-449cf007f255 "api list")
214281
215282
6. Click on the METHOD beneath your Lambda function, in our case it's 'POST'. Then click on the word 'TEST' with the lightning bolt underneath it:
216283
-209 KB
Binary file not shown.

‎examples/add.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tap, { Test } from 'tap';
2+
import { add } from './add.ts';
3+
4+
tap.test('add two numbers', (t: Test) => {
5+
t.equal(add(1, 2), 3);
6+
t.end();
7+
})
8+
9+
tap.test('add a negative number should work', (t: Test) => {
10+
t.equal(add(1, -2), -1);
11+
t.end();
12+
})

‎examples/add.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function add(x: number, y: number): number {
2+
return x + y;
3+
}

‎gulpfile.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/***
2+
* This file was created before we had a better way to upload Lambda Functions
3+
* see: https://github.com/dwyl/aws-lambda-deploy
4+
* */
5+
16
var AWS = require('aws-sdk');
27
var gulp = require('gulp');
38
var zip = require('gulp-zip');

‎lambda-testing/test/ava.test.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
2-
var test = require('ava');
2+
import tap, { Test } from 'tap';
3+
const test = tap.test;
34
var context = require('aws-lambda-mock-context');
45
var promisify = require('aws-lambda-pify');
56
var createDynamoDBEvent = require('./utils/eventCreators').createDynamoDBEvent;
@@ -20,11 +21,11 @@ var LambdaTest = promisify(require('../functions/LambdaTest.js').handler
2021
var DynamoDBLambdaTest = promisify(require('../functions/DynamoDBLambdaTest.js').handler, ctx)
2122

2223
test('LambdaTest', async t => {
23-
t.is( await LambdaTest(testEvent), 'name')
24+
t.equal(await LambdaTest(testEvent), 'name')
2425
})
2526

2627
test('DynamoDBLambdaTest', async t => {
27-
t.is( await DynamoDBLambdaTest(testDynamoDBEvent), 3)
28+
t.equal(await DynamoDBLambdaTest(testDynamoDBEvent), 3)
2829
})
2930

3031
console.log('Tests took', process.uptime(), "seconds to run");
Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,44 @@
11
'use strict';
2-
3-
var Code = require('code');
4-
var Lab = require('lab');
5-
var lab = exports.lab = Lab.script();
6-
var describe = lab.experiment;
7-
var expect = Code.expect;
8-
var it = lab.test;
9-
var createDynamoDBEvent = require('./utils/eventCreators').createDynamoDBEvent;
2+
import tap from 'tap';
3+
const test = tap.test;
4+
const createDynamoDBEvent = require('./utils/eventCreators').createDynamoDBEvent;
105

116
/**
127
Handlers
138
**/
14-
var LambdaTest = require('../functions/lambdaTest.js').handler
15-
var DynamoDBLambdaTest = require('../functions/DynamoDBLambdaTest.js').handler
9+
import * as LambdaTest from '../functions/lambdaTest.js'
10+
import * as DynamoDBLambdaTest from '../functions/DynamoDBLambdaTest.js'
1611

1712
/**
1813
Create mock event and context objects
1914
**/
20-
var contextCreator = require('./utils/mockContext.js');
21-
var testEvent = { key1: 'name' }
22-
var testDynamoDBEvent = createDynamoDBEvent();
23-
24-
describe('LambdaTest', function(){
25-
it("LambdaTest: returns value when given event with key1 property", function(done) {
26-
27-
function test(result){
28-
expect(result).to.equal("name")
29-
done();
30-
}
31-
var context = contextCreator(test);
32-
LambdaTest(testEvent, context);
33-
})
34-
it("LambdaTest: returns error when given empty event", function(done) {
35-
function test(error){
36-
expect(error).to.equal("no key1")
37-
done();
38-
}
39-
var context = contextCreator(test);
40-
LambdaTest({}, context);
41-
})
15+
const contextCreator = require('./utils/mockContext.js');
16+
const testEvent = { key1: 'name' }
17+
const testDynamoDBEvent = createDynamoDBEvent();
18+
19+
test('LambdaTest: returns value given event with key1 property', function(t) {
20+
function test(result) {
21+
t.equal(result, "name")
22+
t.end();
23+
}
24+
const context = contextCreator(test);
25+
LambdaTest(testEvent, context);
26+
});
27+
28+
test("LambdaTest: returns error when given empty event", function(t) {
29+
function test(error) {
30+
t.equal(error, "no key1");
31+
t.end();
32+
}
33+
const context = contextCreator(test);
34+
LambdaTest({}, context);
4235
})
4336

44-
describe('DynamoDB Triggered Lambda Test', function(){
45-
it("DynamoDBTest: returns number of records in the event", function(done) {
46-
47-
function test(result){
48-
expect(result).to.equal(3)
49-
done();
50-
}
51-
var context = contextCreator(test);
52-
53-
DynamoDBLambdaTest(testDynamoDBEvent, context);
54-
})
37+
test("DynamoDBTest: returns number of records in the event", function(t) {
38+
function test(result) {
39+
t.equal(result, 3)
40+
t.end();
41+
}
42+
const context = contextCreator(test);
43+
DynamoDBLambdaTest(testDynamoDBEvent, context);
5544
})

0 commit comments

Comments
 (0)