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