Re: Amber Smalltalk on AWS Lambda

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Amber Smalltalk on AWS Lambda

Herby Vojčík
You don't edit config.js (it's mentioned in it's beginning).

You create dirname.amd.json file for 3rd library and assemble config.js by amdconfig task (run as part of amber devel, for example).

Will post details later, writing from my phone.

Herby

Dňa 9. júla 2019 0:08:49 SELČ používateľ Stefan Krecher <[hidden email]> napísal:
While playing around with the backend-feature, the next step would be to import the AWS-SDK Javascript library.
I installed it with npm install aws-sdk and flipped through all the documentation regarding the use of 3rd-party libraries with amber.
The aws-sdk does not seem to include an "amd" file (I have no idea what that would be for), so I added this to the config.js file:
"aws": 'node_modules/aws-sdk/dist/aws-sdk.js',
and
'aws': {
      'exports': 'AWS'
    },
in the "shim" section.
This didn't seem to work - I wanted to make some AWS API calls from a workspace.
Can you point me in the right direction?
Thanks in advance
Stefan

Am Sa., 6. Juli 2019 um 13:48 Uhr schrieb Stefan Krecher <[hidden email]>:
Hey - I finally made it. Looks like I had messed up multiple versions of the cli on my computer.
Sorry to bother you

Am Fr., 5. Juli 2019 um 15:55 Uhr schrieb Herby Vojčík <[hidden email]>:


Dňa 5. júla 2019 15:33:12 SELČ používateľ Stefan Krecher <[hidden email]> napísal:
>Hi,
>I did this:
>npm -g uninstall @ambers/cli -f
>npm cache clean -f
>npm -g install @ambers/cli -f
>
>npm ls -g @ambers/grunt-init-amber-project shows:
>`-- @ambers/cli@0.105.0
>  `-- @ambers/grunt-init-amber-project@0.24.0
>
>"amber version" shows this:
>Welcome to Amber CLI version 0.105.0 (Amber 0.23.0-pre, NodeJS
>10.15.0).
>
>But when I create a scaffold with "amber init", I don't see the
>*-Backend
>package and there was no "lambda" directory created.
>
>What did I do wrong?

I don't know. It is strange, that should definitely not be the case. :-/ 0.24.0 is good template. "amber" cli seems to be running the correct npm-installed thing. :-( (try uninstall and run "amber init" anyway if there isn't some dangling old installation in your setup). Or zoom me or skype me at drudkin.

Herby

>Thanks
>Stefan
>
>
>Am Di., 28. Mai 2019 um 22:43 Uhr schrieb Herby Vojčík
><[hidden email]>:
>
>> Ok, so ...
>>
>> a few days ago Stefan Krecher asked how to run Amber on AWS Lambda.
>So I
>> looked at it, and - there is the backend part now by default in the
>> initial project.
>>
>> So update your amber:
>>
>>    npm -g install @ambers/cli
>>
>> and if `npm ls -g @ambers/grunt-init-amber-project` does not show at
>> least version 0.23.5, then force npm:
>>
>>    npm -g uninstall @ambers/cli -f
>>    npm cache clean -f
>>    npm -g install @ambers/cli -f
>>
>> and you should have the new project scaffolding installed. Run your
>> beloved `amber init` in an empty directory, and after you run `amber
>> serve` and start Helios, you see your project has new
>> YourProject-Backend package with YourProjectBackend class.
>>
>> Your project also has `lambda` directory with `index.js` file. This
>just
>> defines instance of which class should be used to serve the requests
>and
>> defines handler(s) by specifying which selector to use. The rest is
>> magic in Gruntfile.js which now allows to pack the backend Amber
>package
>> and its dependencies. In a parallel terminal (so your `amber serve`
>> still runs), run
>>
>>    grunt deploy:lambda
>>
>> and the lambda/the.js is built. This file is needed by
>lambda/index.js
>> and it includes everything that the backend package(s), as specified
>in
>> lambda.js (backend analogy of deploy.js), need. Now you just zip the
>> contents of the lambda directory, and you have the deployment package
>> that you can use in AWS Lambda.
>>
>> The code in initial app has the button that actually calls your
>Lambda
>> function and shows you the result. It supposes that you create AWS
>API
>> Gateway using proxy integration (the defaults if you use Lambda the
>> first time), and that your endpoints (and functions) are called
>`echo`
>> and `status` (obviously, those are the exported handler names in
>index.js).
>>
>> Go to your Helios IDE, find YourProject >> endpoint, and specify path
>to
>> the API Gateway. From that point on, the "Inspect status of backend"
>> should call your Lambda function and open the result in Helios'
>inspect
>> pane (or show you the dialog with an error).
>>
>> Use Amber on both frontend and backend and be happy,
>>
>> Herby
>>
>> P.S.: The cold start takes some time, around 500ms (the single Amber
>> hierarchy is not a true single hierarchy - there are detached JS
>classes
>> like Number, Array, Date, String, Function for which full set of DNU
>> handlers and copied methods from logical Amber superclass must be
>> installed to give the impression of single Smalltalk hierarchy, and
>that
>> takes time and is done eagerly during startup... I can see into it if
>> can be lazified), but the subsequent ones sharing execution context
>are
>> fast.
>>
>> --
>> 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 [hidden email].
>> To view this discussion on the web visit
>>
>https://groups.google.com/d/msgid/amber-lang/ad572ba6-000a-df67-85f4-04ef08557c58%40mailbox.sk
>> .
>> For more options, visit https://groups.google.com/d/optout.



--
Dipl.-Wirtsch.-Inf. Stefan Krecher
Neulander Str. 17, 27374 Visselhövede
Tel +49(0)4262 958848
mobil +49(0)172 4396852

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/7D573430-A28C-4744-AA86-DE0F3C58FC48%40mailbox.sk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Amber Smalltalk on AWS Lambda

Herby Vojčík
On 9. 7. 2019 0:23, Herby Voj????k wrote:
> You don't edit config.js (it's mentioned in it's beginning).
>
> You create dirname.amd.json file for 3rd library and assemble config.js
> by amdconfig task (run as part of amber devel, for example).
>
> Will post details later, writing from my phone.
>
> Herby

Have you read this
https://github.com/amber-smalltalk/amber/wiki/Building-blocks-of-Amber-application-(and-library)?
Just replace bower with npm (bower is not used any more) and it should
be correct.

As for AWS SDK, it seems it is not packed in UMD form, so AMD loader can
not load it, but exports should work fine.

It is just that you need to create aws.amd.json or aws-sdk.amd.json (I
don't know what will be the name of the directory where it installs
into) with proper paths section relative to that dir and shim sections
(exports should work).

If you would like to load it in workspace, you would need to use require
directly, which I want to deprecate in favour of general package loader
based off JS dynamic import.

So I would advise to add aws in imports: of your app package (or
background package), as in

imports: {" ...others... ". 'aws' -> 'AWS'}

(I presume you want to use it anyway) then add some class-level method
in some class to expose it

MyClass >> publishedAws
   ^ aws

and in workspace just use MyClass publishedAws (inside the package with
import, you can just use 'aws' variable directly; imports: defines
'package-level' variables in reality).

Herby

> D??a 9. j??la 2019 0:08:49 SEL?? pou????vate?? Stefan Krecher
> <[hidden email]> nap??sal:
>
>     While playing around with the backend-feature, the next step would
>     be to import the AWS-SDK Javascript library.
>     I installed it with npm install aws-sdk and flipped through all the
>     documentation regarding the use of 3rd-party libraries with amber.
>     The aws-sdk does not seem to include an "amd" file (I have no idea
>     what that would be for), so I added this to the config.js file:
>     "aws": 'node_modules/aws-sdk/dist/aws-sdk.js',
>     and
>     'aws': {
>      ?? ?? ?? 'exports': 'AWS'
>      ?? ?? },
>     in the "shim" section.
>     This didn't seem to work - I wanted to make some AWS API calls from
>     a workspace.
>     Can you point me??in the right direction?
>     Thanks in advance
>     Stefan
>
>     Am Sa., 6. Juli 2019 um 13:48??Uhr schrieb Stefan Krecher
>     <[hidden email] <mailto:[hidden email]>>:
>
>         Hey - I finally made it. Looks like I had messed up multiple
>         versions of the cli on my computer.
>         Sorry to bother you
>
>         Am Fr., 5. Juli 2019 um 15:55??Uhr schrieb Herby Voj????k
>         <[hidden email] <mailto:[hidden email]>>:
>
>
>
>             D??a 5. j??la 2019 15:33:12 SEL?? pou????vate?? Stefan Krecher
>             <[hidden email] <mailto:[hidden email]>>
>             nap??sal:
>              >Hi,
>              >I did this:
>              >npm -g uninstall @ambers/cli -f
>              >npm cache clean -f
>              >npm -g install @ambers/cli -f
>              >
>              >npm ls -g @ambers/grunt-init-amber-project shows:
>              >`-- @ambers/cli@0.105.0
>              >?? `-- @ambers/grunt-init-amber-project@0.24.0
>              >
>              >"amber version" shows this:
>              >Welcome to Amber CLI version 0.105.0 (Amber 0.23.0-pre, NodeJS
>              >10.15.0).
>              >
>              >But when I create a scaffold with "amber init", I don't
>             see the
>              >*-Backend
>              >package and there was no "lambda" directory created.
>              >
>              >What did I do wrong?
>
>             I don't know. It is strange, that should definitely not be
>             the case. :-/ 0.24.0 is good template. "amber" cli seems to
>             be running the correct npm-installed thing. :-( (try
>             uninstall and run "amber init" anyway if there isn't some
>             dangling old installation in your setup). Or zoom me or
>             skype me at drudkin.
>
>             Herby
>
>              >Thanks
>              >Stefan
>              >
>              >
>              >Am Di., 28. Mai 2019 um 22:43 Uhr schrieb Herby Voj????k
>              ><[hidden email] <mailto:[hidden email]>>:
>              >
>              >> Ok, so ...
>              >>
>              >> a few days ago Stefan Krecher asked how to run Amber on
>             AWS Lambda.
>              >So I
>              >> looked at it, and - there is the backend part now by
>             default in the
>              >> initial project.
>              >>
>              >> So update your amber:
>              >>
>              >>?? ?? npm -g install @ambers/cli
>              >>
>              >> and if `npm ls -g @ambers/grunt-init-amber-project` does
>             not show at
>              >> least version 0.23.5, then force npm:
>              >>
>              >>?? ?? npm -g uninstall @ambers/cli -f
>              >>?? ?? npm cache clean -f
>              >>?? ?? npm -g install @ambers/cli -f
>              >>
>              >> and you should have the new project scaffolding
>             installed. Run your
>              >> beloved `amber init` in an empty directory, and after
>             you run `amber
>              >> serve` and start Helios, you see your project has new
>              >> YourProject-Backend package with YourProjectBackend class.
>              >>
>              >> Your project also has `lambda` directory with `index.js`
>             file. This
>              >just
>              >> defines instance of which class should be used to serve
>             the requests
>              >and
>              >> defines handler(s) by specifying which selector to use.
>             The rest is
>              >> magic in Gruntfile.js which now allows to pack the
>             backend Amber
>              >package
>              >> and its dependencies. In a parallel terminal (so your
>             `amber serve`
>              >> still runs), run
>              >>
>              >>?? ?? grunt deploy:lambda
>              >>
>              >> and the lambda/the.js is built. This file is needed by
>              >lambda/index.js
>              >> and it includes everything that the backend package(s),
>             as specified
>              >in
>              >> lambda.js (backend analogy of deploy.js), need. Now you
>             just zip the
>              >> contents of the lambda directory, and you have the
>             deployment package
>              >> that you can use in AWS Lambda.
>              >>
>              >> The code in initial app has the button that actually
>             calls your
>              >Lambda
>              >> function and shows you the result. It supposes that you
>             create AWS
>              >API
>              >> Gateway using proxy integration (the defaults if you use
>             Lambda the
>              >> first time), and that your endpoints (and functions) are
>             called
>              >`echo`
>              >> and `status` (obviously, those are the exported handler
>             names in
>              >index.js).
>              >>
>              >> Go to your Helios IDE, find YourProject >> endpoint, and
>             specify path
>              >to
>              >> the API Gateway. From that point on, the "Inspect status
>             of backend"
>              >> should call your Lambda function and open the result in
>             Helios'
>              >inspect
>              >> pane (or show you the dialog with an error).
>              >>
>              >> Use Amber on both frontend and backend and be happy,
>              >>
>              >> Herby
>              >>
>              >> P.S.: The cold start takes some time, around 500ms (the
>             single Amber
>              >> hierarchy is not a true single hierarchy - there are
>             detached JS
>              >classes
>              >> like Number, Array, Date, String, Function for which
>             full set of DNU
>              >> handlers and copied methods from logical Amber
>             superclass must be
>              >> installed to give the impression of single Smalltalk
>             hierarchy, and
>              >that
>              >> takes time and is done eagerly during startup... I can
>             see into it if
>              >> can be lazified), but the subsequent ones sharing
>             execution context
>              >are
>              >> fast.
>              >>
>              >> --
>              >> 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 [hidden email]
>             <mailto:amber-lang%[hidden email]>.
>              >> To view this discussion on the web visit
>              >>
>              >https://groups.google.com/d/msgid/amber-lang/ad572ba6-000a-df67-85f4-04ef08557c58%40mailbox.sk
>              >> .
>              >> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>     --
>     Dipl.-Wirtsch.-Inf. Stefan Krecher
>     Neulander Str. 17, 27374 Visselh??vede
>     Tel +49(0)4262 958848
>     mobil +49(0)172 4396852
>
> --
> 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 [hidden email]
> <mailto:[hidden email]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/amber-lang/7D573430-A28C-4744-AA86-DE0F3C58FC48%40mailbox.sk 
> <https://groups.google.com/d/msgid/amber-lang/7D573430-A28C-4744-AA86-DE0F3C58FC48%40mailbox.sk?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/amber-lang/584e7826-2273-502b-95f6-4c449fbbdb7e%40mailbox.sk.
For more options, visit https://groups.google.com/d/optout.