Skip to content

Commit e4d2067

Browse files
whummerHarshCasper
andauthored
add button to load function URLs from Lambda API (#12)
--------- Co-authored-by: HarshCasper <erbeusgriffincasper@gmail.com>
1 parent a6388d9 commit e4d2067

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

bin/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ else
6666
cd package
6767
zip -r ../lambda.zip *;
6868
)
69-
fi
69+
fi
7070

7171
awslocal lambda create-function \
7272
--function-name resize \

website/app.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
let imageItemTemplate = Handlebars.compile($("#image-item-template").html());
1414

15-
$("#configForm").submit(function (event) {
15+
$("#configForm").submit(async function (event) {
1616
if (event.preventDefault)
1717
event.preventDefault();
1818
else
@@ -22,7 +22,24 @@
2222

2323
let action = $(this).find("button[type=submit]:focus").attr('name');
2424

25-
if (action == "save") {
25+
if (action == "load") {
26+
let baseUrl = `${document.location.protocol}//${document.location.host}`;
27+
if (baseUrl.indexOf("file://") >= 0) {
28+
baseUrl = `http://localhost:4566`;
29+
}
30+
baseUrl = baseUrl.replace("://webapp.s3.", "://");
31+
const headers = {authorization: "AWS4-HMAC-SHA256 Credential=test/20231004/us-east-1/lambda/aws4_request, ..."};
32+
const loadUrl = async (funcName, resultElement) => {
33+
const url = `${baseUrl}/2021-10-31/functions/${funcName}/urls`;
34+
const result = await $.ajax({url, headers}).promise();
35+
const funcUrl = JSON.parse(result).FunctionUrlConfigs[0].FunctionUrl;
36+
$(`#${resultElement}`).val(funcUrl);
37+
localStorage.setItem(resultElement, funcUrl);
38+
}
39+
await loadUrl("presign", "functionUrlPresign");
40+
await loadUrl("list", "functionUrlList");
41+
alert("Function URL configurations loaded");
42+
} else if (action == "save") {
2643
localStorage.setItem("functionUrlPresign", $("#functionUrlPresign").val());
2744
localStorage.setItem("functionUrlList", $("#functionUrlList").val());
2845
alert("Configuration saved");

website/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
crossorigin="anonymous">
1111
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css"
1212
rel="stylesheet">
13+
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
1314
</head>
1415
<body>
1516

@@ -43,6 +44,7 @@ <h5 class="card-text">
4344
<input type="text" class="form-control" id="functionUrlList" autocomplete="false"/>
4445
</div>
4546
<div class="mb-3">
47+
<button type="submit" name="load" class="btn btn-primary mb-3">Load from API</button>
4648
<button type="submit" name="save" class="btn btn-primary mb-3">Apply</button>
4749
<button type="submit" name="clear" class="btn btn-secondary mb-3">Clear</button>
4850
</div>
@@ -65,7 +67,8 @@ <h5 class="card-title">Form</h5>
6567
and then forwards the POST request directly to S3.
6668
Resizing the image to max 400x400 pixels happens asynchronously through S3 bucket notifications.
6769
If the resizing of an image fails, then an SNS message will be sent, which will trigger an SES email
68-
notification. You can find those by visiting <a href="//localhost.localstack.cloud:4566/_aws/ses">http://localhost.localstack.cloud:4566/_aws/ses</a>
70+
notification. You can find those by visiting
71+
<a href="//localhost.localstack.cloud:4566/_aws/ses">http://localhost.localstack.cloud:4566/_aws/ses</a>
6972
</p>
7073
<form id="uploadForm" action="#" method="post">
7174
<div class="mb-3">
@@ -98,7 +101,7 @@ <h1 class="h4">List your files <i class="bi bi-image"></i></h1>
98101
<p class="mt-2">
99102
The images you uploaded should be shown here.
100103
When the refresh action is triggered, the browser makes a request to the <code>list</code> Lambda URL
101-
which returns a JSON document of all items in the images and the resized images bucket. The Javascript
104+
which returns a JSON document of all items in the images and the resized images bucket. The JavaScript
102105
then populates the list below using a Handlebars template.
103106
</p>
104107
<hr>

0 commit comments

Comments
 (0)