Using amber with AWS Lambda Functions

44 views
Skip to first unread message

Stefan Krecher

unread,
May 17, 2019, 10:37:05 AM5/17/19
to amber-lang
Hi,
Since there is an AWS SDK for node/ javascript, it should be possible to write code with amber to interact with the AWS API.
This would be extremly cool and usefull - you could write backend code with amber to orchestrate AWS services. Then expose the backend via AWS API-Gateway/ REST-Resource and access it from the Amber UI that might be hosted in an S3 bucket (or any other static file hosting). If amber was able to use/ include the AWS Amplify framework on the UI part, we'll get authentication/ authorization/ user management and secure calls to the backend for free.
Sounds like a really nice serverless application stack - and it would be a dream to use Smalltalk on the front- and backend.
To get started I would need to export Amber/ Smalltalk code in a way that I can reference single functions to be used as AWS Lambda funtion.
Below is a minimal Lambda function - it's a file that's called index.js. During the deployment to AWS I declare "index.handler" es the entry-point of the Lambda-Function.

exports.handler = async (event) => {
    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

Can anyone point me in the right direction, if it would be possible, to export code from amber that looks like the above snippet?
Dependencies and even own runtimes can be included too if needed.

Sadly (or luckily?) I was able to avoid using Javascript since it became so popular - my experience with javascript/ node and the whole ecosystem is very limited.

Regards
Stefan

Dave Mason

unread,
May 17, 2019, 11:08:07 AM5/17/19
to amber-lang
PharoJS also directly support node apps, although our documentation needs work.

../Dave
--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amber-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/4258f7d7-d8a8-459c-86ae-78707bd7ebfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Herby Vojčík

unread,
May 17, 2019, 1:52:49 PM5/17/19
to amber...@googlegroups.com, Stefan Krecher
On 17. 5. 2019 16:37, Stefan Krecher wrote:
> Hi,
> Since there is an AWS SDK for node/ javascript, it should be possible to
> write code with amber to interact with the AWS API.
> This would be extremly cool and usefull - you could write backend code
> with amber to orchestrate AWS services. Then expose the backend via AWS
> API-Gateway/ REST-Resource and access it from the Amber UI that might be
> hosted in an S3 bucket (or any other static file hosting). If amber was
> able to use/ include the AWS Amplify framework on the UI part, we'll get
> authentication/ authorization/ user management and secure calls to the
> backend for free.

Seems like a lot of concepts here.

To use any JS library from UI part of Amber app, it's pretty easy -
include a JS library in a project dependencies, `import:` it in a
package that uses it and call via Smalltalk message; more or less how it
is shown in old wiki article here:
https://github.com/amber-smalltalk/amber/wiki/From-smalltalk-to-javascript-and-back.

> Sounds like a really nice serverless application stack - and it would be
> a dream to use Smalltalk on the front- and backend.
> To get started I would need to export Amber/ Smalltalk code in a way
> that I can reference single functions to be used as AWS Lambda funtion.
> Below is a minimal Lambda function - it's a file that's called index.js.
> During the deployment to AWS I declare "index.handler" es the
> entry-point of the Lambda-Function.
>
> |
> exports.handler = async (event) => {
>     // TODO implement
>     const response = {
>         statusCode: 200,
>         body: JSON.stringify('Hello from Lambda!'),
>     };
>     return response;
> };
> |

If you ask how to compile amber to be run out of browser, there is
possibility to compile Amber project as a node executable (`amber` cli
itself is written in Amber), there is not yet any try of which I know to
wrap it in Lambda-compatible way, but it should be possible. Anyway, any
call would need to load much more than the code itself - the whole
kernel with classes and methods; but similarly to how node apps are
built, an export usable for Lambda should be able to be built as well.
It is basically matter of setting up the JS build stack - `grunt deploy`
building one js file for UI project deployments is one such setup,
`build:cli` task in Amber's own Gruntfile.js which build the
aforementioned `amber` cli as node executable is another such setup; a
third setup that instructs JS build machinery to produce
Lambda-consumable artifact would be third such setup.

It seems to me that starting with "node app" setup is the easiest way -
maybe install Amber for development (as shown in
https://lolg.it/amber/amber/src/master/CONTRIBUTING.md#setup-your-amber-clone)
and take your clues from the way `amber` cli is built, changing the
wrapping so the output is lambda-compatible.

> Can anyone point me in the right direction, if it would be possible, to
> export code from amber that looks like the above snippet?
> Dependencies and even own runtimes can be included too if needed.
>
> Sadly (or luckily?) I was able to avoid using Javascript since it became
> so popular - my experience with javascript/ node and the whole ecosystem
> is very limited.
>
> Regards
> Stefan

Herby

Stefan Krecher

unread,
May 17, 2019, 2:51:13 PM5/17/19
to Herby Vojčík, amber...@googlegroups.com
Herby,
Thank you so much for taking the time to write such a detailed answer!
I’ll follow your instructions.
I’ve been developing these kind of applications with react for the UI and with python for the backend - using Smalltalk on both sides would be so cool!
Serverless + Smalltalk - sounds like a Perfect match ;-)
Regards
Stefan
--
Dipl.-Wirtsch.-Inf. Stefan Krecher
Neulander Str. 17, 27374 Visselhövede
Tel +49(0)4262 958848
mobil +49(0)172 4396852

Herby Vojčík

unread,
May 17, 2019, 3:11:49 PM5/17/19
to amber...@googlegroups.com, Stefan Krecher
On 17. 5. 2019 20:51, Stefan Krecher wrote:
> Herby,
> Thank you so much for taking the time to write such a detailed answer!
> I’ll follow your instructions.
> I’ve been developing these kind of applications with react for the UI
> and with python for the backend - using Smalltalk on both sides would be
> so cool!
> Serverless + Smalltalk - sounds like a Perfect match ;-)
> Regards
> Stefan
>
> Herby Vojčík <he...@mailbox.sk <mailto:he...@mailbox.sk>> schrieb am Fr.
BTW. If Lambda accepts AMD format as well (I don't know, just saying)
then it should be even easier as the current ecosystem of Amber is built
around AMD and uses RequireJS to build - in that case starting from
`deploy` task of standard `amber init`-created project would be probably
easier / faster. In case you need node's CommonJS format, then of course
starting with nodejs type build is the way.

Herby
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to amber-lang+...@googlegroups.com
> <mailto:amber-lang+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/amber-lang/CADB_sZzcdXovJAjk9xmrMvLm4oKaOCfxA%3DrRo%2BtDg1XE0kprng%40mail.gmail.com
> <https://groups.google.com/d/msgid/amber-lang/CADB_sZzcdXovJAjk9xmrMvLm4oKaOCfxA%3DrRo%2BtDg1XE0kprng%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages