awslabs / aws-api-gateway-developer-portal

A Serverless Developer Portal for easily publishing and cataloging APIs
Apache License 2.0
924 stars 399 forks source link

How to start dev portal in windows machine #504

Closed HimanshuShuklaCoder closed 2 years ago

HimanshuShuklaCoder commented 2 years ago

Hi,

I am new to AWS and developer portal. I want to run the developer portal on my local machine and want to change the UI using react features. Every time i try to tun the developer portal it throws me the error - "TypeError: Cannot read property 'restApiId' of undefined" This is picked from window.config .restApiId. Can anyone could help me in setting up the code locally. Have added deployer.config file with correct entires corresponding to my AWS account

HimanshuShuklaCoder commented 2 years ago

Hi, Please follow the below steps to run this dev portal in windows local machine:

Steps:

  1. Install Git [2], Node v14 [3], AWS CLI [4], AWS SAM CLI [5].
  2. Configure access key and secret key for AWS CLI using following command [6]:

$ aws configure

Once you hit enter you will have to add following information:

AWS Access Key ID: AWS Secret Access Key: Default region name: Default output format: json

  1. I found an issue related to Windows where child process for npm is not working correctly [7]. To mitigate this issue I found that npm.cmd works correctly.

Go to npm.js file present at "aws-api-gateway-developer-portal\scripts\npm.js" and replace "npm" at line number 11 to "npm.cmd" Your line number 11 in npm.js should be as follows:


await run('npm.cmd', process.argv.slice(2), { action: 'Execution', target, cwd: resolved })

  1. Go to run.js file present at "aws-api-gateway-developer-portal\scripts\run.js" and replace "npm" at line number 14 to "npm.cmd" Your line number 14 in run.js should be as follows:

'npm.cmd', ['run', task, '—', ...args],

  1. Now as per the documentation kindly copy the "example-dev-deployer.config.js" to "deployer.config.js" and replace following values:

==> Replace "YOUR_LAMBDA_ARTIFACTS_BUCKET_NAME" with your s3 bucket name ==> Replace "CUSTOM_PREFIX" with any prefix you like. (For example: test)

  1. Run following command inside aws-api-gateway-developer-portal folder:

$ node run install release

  1. I noticed that sam cli did not deploy the template correctly hence after running the previous command find the "sam deploy" and copy it.

This is the example sam deploy command:

$ sam deploy --template-file C:\Users\Administrator\Desktop\demo\aws-api-gateway-developer-portal\cloudformation\packaged.yaml --stack-name dev-portal0 --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken=XXXXXXXXXXX StaticAssetRebuildMode=overwrite-content DevPortalSiteS3BucketName=test-dev-portal-static-assets0 ArtifactsS3BucketName=test-dev-portal-artifacts0 DevPortalCustomersTableName=DevPortalCustomers0 DevPortalPreLoginAccountsTableName=DevPortalPreLoginAccounts0 DevPortalFeedbackTableName=DevPortalFeedback0 CognitoIdentityPoolName=DevPortalIdentityPool0 LocalDevelopmentMode=true CognitoDomainNameOrPrefix=test-auth0 —s3-bucket testbucket

Kindly replace the packaged.yaml to template.yaml. Following is the sample command that you should make:

$ sam deploy --template-file C:\Users\Administrator\Desktop\demo\aws-api-gateway-developer-portal\cloudformation\template.yaml --stack-name dev-portal0 --capabilities CAPABILITY_NAMED_IAM --parameter-overrides StaticAssetRebuildToken=XXXXXXXXXXX StaticAssetRebuildMode=overwrite-content DevPortalSiteS3BucketName=test-dev-portal-static-assets0 ArtifactsS3BucketName=test-dev-portal-artifacts0 DevPortalCustomersTableName=DevPortalCustomers0 DevPortalPreLoginAccountsTableName=DevPortalPreLoginAccounts0 DevPortalFeedbackTableName=DevPortalFeedback0 CognitoIdentityPoolName=DevPortalIdentityPool0 LocalDevelopmentMode=true CognitoDomainNameOrPrefix=test-auth0 —s3-bucket testbucket

Now run this command and you should see that the stack is being deployed.

  1. Finally run "node run start" command and it will open your default browser. Wait for some time till the script loads and then you should see the developer portal running locally.

Please note - that the configuration and names, given in the SAM deploy command should be same as you have given in the deployer.config.js file. Otherwise it will throw error.