Skip to content

Commit 2755521

Browse files
committed
Bootstrap script support
1 parent 4631146 commit 2755521

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

bootstrap.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
2+
import * as AWS from 'aws-sdk';
3+
import * as https from 'https';
4+
5+
const S3 = new AWS.S3();
6+
7+
const genScript: Handler = (
8+
event: APIGatewayEvent,
9+
context: Context,
10+
cb: Callback
11+
) => {
12+
let version = event.queryStringParameters
13+
? event.queryStringParameters.v || 'current'
14+
: 'current';
15+
S3.getObject(
16+
{
17+
Bucket: 'mikeworks-libs',
18+
Key: `techcheck/${version}/bootstrap.sh`
19+
},
20+
(err, data) => {
21+
//
22+
if (!data) {
23+
cb(null, {
24+
statusCode: 200,
25+
body: `/** There is a problem with the script generation service. Please try again later **/
26+
27+
28+
console.log('⚠️ There is a problem with the script generation service. Please try again later ⚠️');
29+
`
30+
});
31+
return;
32+
}
33+
34+
const response = {
35+
statusCode: 200,
36+
body: data.Body.toString().replace(
37+
'https://mikeworks-libs.s3.amazonaws.com/techcheck/index.js',
38+
`https://f2co98an90.execute-api.us-west-2.amazonaws.com/dev/preflight/script?v=${version}`
39+
)
40+
};
41+
cb(null, response);
42+
}
43+
);
44+
};
45+
export default genScript;
File renamed without changes.

serverless.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ provider:
1212
region: us-west-2
1313

1414
functions:
15-
get-script:
16-
handler: gen-script.default
15+
run:
16+
handler: bootstrap.default
1717
events:
1818
- http:
1919
method: get
2020
path: /preflight
21+
get-script:
22+
handler: get-script.default
23+
events:
24+
- http:
25+
method: get
26+
path: /preflight/script

0 commit comments

Comments
 (0)