serverless node js api multiple microservices with shared code - node.js

I am trying to deploy multiple serverless stacks on aws, having my code folder structure as below
The file s1/handler.js imports controllers like this
const demoController = require('../../src/Controllers/DemoController');
This works fine when I run it locally using "sls offline start" from within folder "s1"
However, after deploying to aws, this controller import fails and gives runtime importmodule error in lambda call.
Is this code structuring correct? How to fix this so that same structure works for "offline" as well as "deployed" multiple services?

Related

how to set dynamic enviroment variable for static nextjs app deployed on IIS

I'm trying to deploy the static nextjs app(next export) on local Windows IIS.
The web app communicates RestFul API server deployed on the same network.
The problem is the address of RestFul API server.
It's from .env.* file. The env file has the key-value pair of (NEXT_PUBLIC_API_URL, http://192.168.1.12:8080/api).
When build the app with next build command, the value(http://192.168.1.12:8080) is inserted to output source code directly.
It's ok in development process because the address of API is fixed, but it must be changed dynamically after deployed on production.
Is there anything I can do to export values for static nextjs app dynamically on local IIS?
To solve this problem I created some static-env.json file in public folder like below:
{
"apiURL" : "http://192.168.1.12:8080/api"
}
and import it by import staticEnv from "/public/static-env.json, but the result is the same with above. the value itself is inserted to code directly.
I think if this "inserting" action can be prevented, I can use this method.

Importing BetaAnalyticsDataClient from #google-analytics/data returns Webpack 5 errors

I am trying to create a custom dashboard on the angular app I am building. I want to use the data from Google Analytics 4 using Google Analytics Data API. I've successfully ran the scripts provided in their tutorial Using Node.JS client libraries (https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries?hl=en_US).
I've ran the quickstart script they have provided using Node.JS and was able to get the expected response. However, when I try to ran the same script on my angular app via importing the script to fetch returned values, "ng serve" returns webpack 5 errors.
The issue was importing the BetaAnalyticsDataClient. Whenever I import it, the nodemon returns webpack errors.
The structure is like this:
simple component structure
I have a 'site-statistics.component' with its html and scss files.
I have a script named 'google-analytics.ts' inside the subfolder "services".
site-statistics.component imports an exported function from google-analytics.ts
If the issue is my usage of the Google Analytics Data API client library, I want to know how I would be able get the response from the script and send it to my angular component.
Options I've tried, but failed:
Tried adding a resolve.fallback on webpack.config.ts. However, issue still persists.
Tried setting paths to each packages on my TSCONFIG.JSON.
Tried using react-scripts-rewired
If the issue is the way I use the Google Analytics Data API client library, I want to know how I would be able get the response from the script and send it to my angular component.

How to share my own custom fucntions on AWS lambda nodejs

I Currently have a project in AWS with several lambda functions, most of the functions in NodeJS, I want to know if is there a way to create a lambda layer with my own code functions that I use in different lambdas without publish it in npm, I already search in old questions in stack question-1 question-2, but these were not answered
Thanks for help!
create a folder in your local machine called nodejs
put your "shared" logic in that folder like /nodejs/shared.js
you can zip this nodejs folder and upload as a layer
in your lambda code require the shared.js as const shared = require('/opt/nodejs/shared.js')
Links:
Lambda layers: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
Detailed guide: https://explainexample.com/computers/aws/aws-lambda-layers-node-app
Using layers with SAM: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/sharing-lambda-layers.html

VueJS build and Elastic Beanstalk environment variables

I'm quite new to programming in AWS so I will do my best to explain my problem as thoroughly as possible.
My goal is to store an API (private) key as an environment variable on Elastic Beanstalk, for security purposes. My stack is NodeJS + Express + VueJS
Local setup
Locally I've created a .env.local file in the root folder with a VUE_APP_TEST=Test is working locally parameter. The VUE_APP_ part is needed as I want to call on this parameter from my vue app.
After running a build, I can call my parameter with NodeJS using the following code:
var testparam = process.env.VUE_APP_TEST || "Test is not working"
Which makes testparam equal to "Test is working locally" in string format.
So far, so good!
Elastic Beanstalk setup
Following this information from AWS's docs (under Configuring environment properties) I set the same variable as follows: aws environment variable declaration. As explained in the AWS docs, the code for running the parameter is the same:
var testparam = process.env.VUE_APP_TEST || "Test is not working"
Only this time I expect the result to be "Test is working on aws". However, the same "Test is working locally" appears.
I cannot get it to work and it looks to me like a really trivial problem. Can anyone help me? I've spent an entire day on this. Thank you in advance!

Deploying Github-Passport-Stategy Integrated App with Now

I'm new to application deployment, I have an Express application which uses Github's Passport strategy to authenticate users and saves them to a (remote) MongoDB database, when using localhost, my application works as expected.
I'm using the Zeit Now (OSS plan) CLI tool which was installed globally with NPM.
The issue
When I deploy my application using "now" inside the root of the project-folder and then goto "https://github.com/settings/applications/app" and swap the Homepage-URL and the "auth/github/callback" [callback] URL from "http://localhost:3000/auth/github/callback" with the URL generated by Now - so it becomes "https://app-name-pxwlglhegg.now.sh/auth/github/callback" I get redirect-uri-mismatch :
https://app-name-pxwlglhegg.now.sh/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch
I've tried several times and can't figure it out.
You change the callback on GitHub, but the same setting inside your app is not changed. So they mismatch.

Resources