Setting up proxy for Express & React on AWS Amplify - node.js

Im using AWS Amplify for one of my project. I have React in the front and Express as backend. In my localhost I can just add a proxy to my package.json and make call for the api but how can I do so in the AWS? How can I run both express and React side by side and call the api in the amplify or do i need to use EC2?
thanks

if you want to use a "regular REST api" (i.e. non-graphql, no appsync) you'd most likely configure an API Gateway with a Lambda function integration.
For the lambda you can then configure "Serverless ExpressJS function" and have your express code in the lambda.
Here is an example:
$amplify add api
Scanning for plugins...
Plugin scan successful
? Please select from one of the below mentioned services: REST
? Provide a friendly name for your resource to be used as a label for this category in the project: myapi
? Provide a path (e.g., /book/{isbn}): /items
? Choose a Lambda source Create a new Lambda function
? Provide a friendly name for your resource to be used as a label for this category in the project: mylambda
? Provide the AWS Lambda function name: mylambda
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use:
CRUD function for DynamoDB (Integration with API Gateway)
Hello World
Lambda trigger
❯ Serverless ExpressJS function (Integration with API Gateway)
Local lambda invocation for local development is also possible (usually via a lambda docker image)

Related

Integrate AWS API Gateway and Web ACL

Is there a way to associate web acl with aws api gateway using python?
I tried to test my code using CLI command
"*aws waf-regional associate-web-acl --region us-east-1 --web-acl-id '**************' --resource-arn 'arn:aws:apigateway:us-east-1::/restapis/******/stages/test'*
but it is not working, i even tried associating web acl to api gateway from aws console, but the list of web acl's are not listed in the dropdown, though i have already created web acl's.
You are calling "waf-regional" (aka WAF Classic API) with WAFv2 parameter.
For WAFv2, you need to call it as:
aws wafv2 associate-web-acl
Check out documentation for more info: https://docs.aws.amazon.com/cli/latest/reference/wafv2/associate-web-acl.html
Also, the console not showing the association is a known issueL https://forums.aws.amazon.com/thread.jspa?messageID=926212#926212

Is it possible to create stack in my AWS account and resources like (ec2, vpc, rds) created in client AWS account?

I have written an AWS Lambda nodejs function for creating a stack in CloudFormation, using CloudFormation template and given input parameters from UI.
When I run my Lambda function with respected inputs, a stack is successfully creating and instances like (ec2, rds, and vpc, etc.) are also created and working perfectly.
Now I want to make this function as public and use this function with user AWS credentials.
So public user uses my function with his AWS credentials those resources should be created in his account and user doesn't want to see my template code.
How can I achieve this?
You can leverage AWS Cloud Development Kit better, than directly using CloudFormation for this purpose. Although CDK may not be directly used within Lambda, a workaround is mentioned here.
AWS CloudFormation will create resources in the AWS Account that is associated with the credentials used to create the stack.
The person who creates the stack will need to provide (upload) a template file or they can reference a template that is stored in Amazon S3, which is accessible to their credentials (meaning that it is either public, or their credentials have been given permission to access the template in S3).

Amazon AWS Lambda functions having Repository....?

the lambda functions having Repository if yes how to check the Repository details how it will be deployed if no Repository.
Theres no "hidden" or "shared" repository that can be used between different lambda functions, every file you need should be uploaded in the zip file you upload.
Read a more detailed explanation here.
Lambda functions do not have repositories. You can create a deployment package yourself or write your code directly in the Lambda console, in which case the console creates the deployment package for you and uploads it, creating your Lambda function.
If your custom code requires only the AWS SDK library, then you can use the inline editor in the AWS Lambda console. Using the console, you can edit and upload your code to AWS Lambda. The console will zip up your code with the relevant configuration information into a deployment package that the Lambda service can run.
You can also test your code in the console by manually invoking it using sample event data.
In the case of the deployment package, you may either upload it directly or upload the .zip file first to an Amazon S3 bucket in the same AWS region where you want to create the Lambda function, and then specify the bucket name and object key name when you create the Lambda function using the console or the AWS CLI

Nodejs Zoho API v2 "zcrmsdk" how to specify module in "configuration.properties" file for AWS Lambda

I'm using Zoho API V2 Nodejs package "zcrmsdk" and AWS Lambda.
According to Zoho's documentation for API v2 for nodejs : https://www.zoho.com/crm/help/developer/server-side-sdks/node-js.html
Picture: Zoho Instructions for Token Storage Mechanism
They instruct us we can specify our own custom module for Token Storage Mechanism by providing a module name in configuration.properties => api.tokenmanagement
However, I'm finding hard time to link the module name in api.tokenmanagement.
In my local environment, I did it successfully by specifying the path as: api.tokenmanagement=../../../../resources/tokenmgmt.js
(tokenmgmt.js is my custom token management module for Zoho)
However, I'm getting error "Cannot find module" while I deploy the project to AWS Lamda.
I'm not sure if I did not specify the module name (or/and path) correctly or it's the compatibility issue of "zcrmsdk" with AWS Lamda.
Nodejs package: "zcrmsdk" https://www.npmjs.com/package/zcrmsdk

How can I check if the AWS SDK was provided with credentials?

There are many ways to provide the AWS SDK with credentials to perform operations.
I want to make sure any of the methods were successful in setting up the interface before I try my operation on our continuous deployment system.
How can I check if AWS SDK was able to find credentials?
You can access them via the config.credentials property on the main client. All AWS service libraries included in the SDK have a config property.
Class: AWS.Config
The main configuration class used by all service objects to set the region, credentials, and other options for requests.
By default, credentials and region settings are left unconfigured. This should be configured by the application before using any AWS service APIs.
// Using S3
var s3 = new AWS.S3();
console.log(s3.config.credentials);

Resources