Need redirect my gateway to a enpoint (bad request) - express-gateway

well I need create a endpoint where can create a user, using express-gateway, in this have 2 ports running.
gateway http server listening on :::8181
admin http server listening on 127.0.0.1:9876
I can create a user sending my information to:
http://127.0.0.1:9876/users
I can't use this how my end point because have other configuration on my frontend, so in my frontend send my information for create user to:
http://localhost:8181/api/user/create
Now I need send my information to this http://localhost:8181/api/user/create and redirect internal in the gateway to this http://127.0.0.1:9876/users, I try something but just have bad gateway or not found. I call this end point users, so this is the script.
http:
port: 8181
admin:
port: 9876
host: localhost
apiEndpoints:
events:
host: localhost
paths: ["/api/events*", "/swagger*"]
methods: ["GET", "PATCH"]
users:
host: localhost
paths: "/api/user/create*"
url: "http://localhost:9876"
methods: ["POST", "OPTIONS"]
eventsCreate:
host: localhost
paths: "/api/events*"
methods: ["POST", "PUT", "OPTIONS"]
auth:
host: localhost
paths: "/api/auth*"
methods: ["POST", "GET", "OPTIONS"]
serviceEndpoints:
auth:
url: "http://localhost:59868"
events:
url: "http://localhost:5000"
users:
url: "http://localhost:9876"
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
- jwt
- request-transformer
pipelines:
authPipeline:
apiEndpoints:
- auth
policies:
- cors:
- log:
action:
message: "auth ${req.method}"
- proxy:
action:
serviceEndpoint: auth
changeOrigin: true
eventsPipeline:
apiEndpoints:
- events
policies:
- cors:
- log:
action:
message: "events ${req.method}"
- proxy:
action:
serviceEndpoint: events
changeOrigin: true
usersPipeline:
apiEndpoints:
- users
policies:
- cors:
- log:
action:
message: "users ${req.method}"
- proxy:
action:
serviceEndpoint: users
changeOrigin: true
userPipeline:
apiEndpoints:
- events
policies:
- cors:
- log:
action:
message: "events ${req.method}"
- proxy:
action:
serviceEndpoint: events
changeOrigin: true
eventsCreatePipeline:
apiEndpoints:
- eventsCreate
policies:
- cors:
- log:
action:
message: "events ${req.method}"
- jwt:
action:
secretOrPublicKey: "MORTADELAIsMyPassion321"
checkCredentialExistence: false
- proxy:
action:
serviceEndpoint: events
changeOrigin: true

You are trying to map the incoming URL http://localhost:8181/api/user/create to the Express Gateway administration URL http://localhost:9876/users, but your proxy policy only changes the hostname and port components of the URL, not the path.
This is described in the Path Management section of the Proxy documentation.
To change the path, you'll need to either adjust the existing users service endpoint or create a new one, and add some instructions to the proxy middleware configuration:
For example, add a new ServiceEndpoint called userCreate:
serviceEndpoints:
auth:
url: "http://localhost:59868"
userCreate:
url: "http://localhost:9876/users"
users:
url: "http://localhost:9876"
And then refer to the new service endpoint and set stripPath in the proxy configuration:
- proxy:
action:
serviceEndpoint: userCreate
changeOrigin: true
stripPath: true

Related

How to deploy grpc-web on aws?

I have a backend service that I want to expose via grpc-web.
I'm able to use the service directly via the public IP of the ec2 instance. But when I try to access it via the invocation URL of API Gateway I get a CORS error.
I want to add JWT authentication that's why I want to expose the API via API-Gateway.
Here is my configuration:
Envoy.yml
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_sim
address:
socket_address: { address: 0.0.0.0, port_value: 8080 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"#type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: rtdxc_service
timeout: 0s
max_stream_duration:
grpc_timeout_header_max: 0s
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: grpc-status,grpc-message
http_filters:
- name: envoy.filters.http.grpc_web
typed_config:
"#type": type.googleapis.com/envoy.extensions.filters.http.grpc_web.v3.GrpcWeb
- name: envoy.filters.http.cors
typed_config:
"#type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors
- name: envoy.filters.http.router
typed_config:
"#type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: grpc_server
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
load_assignment:
cluster_name: rtdxc_0
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: grpc_server
port_value: 8081
Here is my docker-compose.yml
version: '3.8'
services:
grpc_server:
image: XXXXXX
user: ${UID}:${GID}
ports:
- 8081:8081
tty: true
proxy:
ports:
- 9091:9091
- 8080:8080
image: envoyproxy/envoy:v1.22.0
volumes:
- ./envoy/envoy.yml:/etc/envoy/envoy.yaml:ro
tty:
true
I have mapped API gateway with the following configuration:
ANY / mappes to the public domain of the ec2 instance on port 8080
If I add CORS configuration in the API Gateway , The OPTION request returns 204 with propper cors headers, but POST request does not return proper headers. If I disable CORS configuration in the API gateway, the OPTIONS request also fails due to CORS issue.

Split serverless.yml file

How would I split this serverless.yml file into two .yml files?
I hit the cloudFormation template validation error... " Number of resources, 202, is greater than the maximum allowed, 200"
Ive been stuck on this for 5 days now and cant go any further with my application until I fix this issue.
How could I split up these services into different YML files with a main YML file?
Serverless.yml
service: p-app-api
# Create an optimized package for our functions
package:
individually: true
plugins:
- serverless-bundle # Package our functions with Webpack
- serverless-offline
- serverless-dotenv-plugin
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: us-east-2
environment:
stripeSecretKey: ${env:STRIPE_SECRET_KEY}
# 'iamRoleStatements' defines the permission policy for the Lambda function.
# In this case Lambda functions are granted with permissions to access DynamoDB.
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/zipCode-packageSelected-index"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/jobId-index"
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service/index/index"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::service/public/*"
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/packageSelected"
functions:
# Defines an HTTP API endpoint that calls the main function in create.js
# - path: url path is /notes
# - method: POST request
# - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
# domain api call
# - authorizer: authenticate using the AWS IAM role
create:
handler: create.main
events:
- http:
path: data
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
get:
# Defines an HTTP API endpoint that calls the main function in get.js
# - path: url path is /notes/{id}
# - method: GET request
handler: get.main
events:
- http:
path: data/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
list:
# Defines an HTTP API endpoint that calls the main function in list.js
# - path: url path is /notes
# - method: GET request
handler: list.main
events:
- http:
path: data
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
update:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: update.main
events:
- http:
path: data/{id}
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
delete:
# Defines an HTTP API endpoint that calls the main function in delete.js
# - path: url path is /notes/{id}
# - method: DELETE request
handler: delete.main
events:
- http:
path: data/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createCustomer:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createCustomer.main
events:
- http:
path: createCustomer
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateCustomer:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateCustomer.main
events:
- http:
path: updateCustomer
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listCustomerCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listCustomerCard.main
events:
- http:
path: listCustomerCard/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
deleteCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: DeleteCard.main
events:
- http:
path: deleteCard/{id}/{card}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
getCustomerInfo:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: getCustomerInfo.main
events:
- http:
path: getCustomerInfo/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateCustomerCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateCustomerCard.main
events:
- http:
path: updateCustomerCard/{id}
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createInvoice:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createInvoice.main
events:
- http:
path: createInvoice
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
deleteInvoice:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: deleteInvoice.main
events:
- http:
path: deleteInvoice/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listInvoices:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listInvoices.main
events:
- http:
path: listInvoices/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ListNewJobs:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ListNewJobs.main
events:
- http:
path: data/ListNewJobs
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
jobIndex:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: jobIndex.main
events:
- http:
path: data/jobIndex
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateJobStatus:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateJobStatus.main
events:
- http:
path: data/jobStatus
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createNewJob:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createNewJob.main
events:
- http:
path: ServiceJobs/createNewJob
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listMyNewJobs:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listMyNewJobs.main
events:
- http:
path: ServiceJobs/listMyNewJobs
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
DeleteMyNewJob:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: DeleteMyNewJob.main
events:
- http:
path: ServiceJobs/DeleteMyNewJob/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
UpdateServiceJobList:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: UpdateServiceJobList.main
events:
- http:
path: ServicesJobs/Update
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ServiceIndex:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ServiceIndex.main
events:
- http:
path: ServiceJobs/ServiceIndex
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
UpdateMyJob:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: UpdateMyJob.main
events:
- http:
path: ServiceJobs/UpdateMyJob
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
PayInvoiceStripe:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: PayInvoiceStripe.main
events:
- http:
path: stripe/PayInvoice
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
StripeNewContractorAccount:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: StripeNewContractorAccount.main
events:
- http:
path: stripe/NewContractorAccount
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
serviceInfoPut:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: serviceInfoPut.main
events:
- http:
path: serviceInfo/post
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ListJobsForEdit:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ListJobsForEdit.main
events:
- http:
path: data/index/packageSelected
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
# Create our resources with separate CloudFormation templates
resources:
# API Gateway Errors
- ${file(resources/api-gateway-errors.yml)}
I've had some good success using the serverless-plugin-split-stacks plugin.
You can split your stacks by a few methods, but I'd imagine for your situation, you'd want to split per Lambda

cloudFormation Template Validation Error: how to split serverless.yml file

I ran into the notorious pain in the A$$ error: The CloudFormation template is invalid: Template format error: Number of resources, 202, is greater than maximum allowed, 200.
how do I split this into two, and cross reference the resources?
Could someone possibly share an example with me or show me how to split mine? I've been looking at aws docs and a tons of forums over the past few days to figure this out but I cant quite grasp what I need to do. I just need to be able to add more functions/api calls.
Serverless.yml
service: p-app-api
# Create an optimized package for our functions
package:
individually: true
plugins:
- serverless-bundle # Package our functions with Webpack
- serverless-offline
- serverless-dotenv-plugin
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: us-east-2
environment:
stripeSecretKey: ${env:STRIPE_SECRET_KEY}
# 'iamRoleStatements' defines the permission policy for the Lambda function.
# In this case Lambda functions are granted with permissions to access DynamoDB.
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/zipCode-packageSelected-index"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/jobId-index"
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service/index/index"
- Effect: Allow
Action:
- s3:*
Resource: "arn:aws:s3:::service/public/*"
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/Service"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
Resource: "arn:aws:dynamodb:us-east-2:433684495079:table/data/index/packageSelected"
functions:
# Defines an HTTP API endpoint that calls the main function in create.js
# - path: url path is /notes
# - method: POST request
# - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
# domain api call
# - authorizer: authenticate using the AWS IAM role
create:
handler: create.main
events:
- http:
path: data
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
get:
# Defines an HTTP API endpoint that calls the main function in get.js
# - path: url path is /notes/{id}
# - method: GET request
handler: get.main
events:
- http:
path: data/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
list:
# Defines an HTTP API endpoint that calls the main function in list.js
# - path: url path is /notes
# - method: GET request
handler: list.main
events:
- http:
path: data
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
update:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: update.main
events:
- http:
path: data/{id}
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
delete:
# Defines an HTTP API endpoint that calls the main function in delete.js
# - path: url path is /notes/{id}
# - method: DELETE request
handler: delete.main
events:
- http:
path: data/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createCustomer:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createCustomer.main
events:
- http:
path: createCustomer
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateCustomer:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateCustomer.main
events:
- http:
path: updateCustomer
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listCustomerCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listCustomerCard.main
events:
- http:
path: listCustomerCard/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
deleteCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: DeleteCard.main
events:
- http:
path: deleteCard/{id}/{card}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
getCustomerInfo:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: getCustomerInfo.main
events:
- http:
path: getCustomerInfo/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateCustomerCard:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateCustomerCard.main
events:
- http:
path: updateCustomerCard/{id}
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createInvoice:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createInvoice.main
events:
- http:
path: createInvoice
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
deleteInvoice:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: deleteInvoice.main
events:
- http:
path: deleteInvoice/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listInvoices:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listInvoices.main
events:
- http:
path: listInvoices/{id}
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ListNewJobs:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ListNewJobs.main
events:
- http:
path: data/ListNewJobs
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
jobIndex:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: jobIndex.main
events:
- http:
path: data/jobIndex
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
updateJobStatus:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: updateJobStatus.main
events:
- http:
path: data/jobStatus
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
createNewJob:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: createNewJob.main
events:
- http:
path: ServiceJobs/createNewJob
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
listMyNewJobs:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: listMyNewJobs.main
events:
- http:
path: ServiceJobs/listMyNewJobs
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
DeleteMyNewJob:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: DeleteMyNewJob.main
events:
- http:
path: ServiceJobs/DeleteMyNewJob/{id}
method: delete
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
UpdateServiceJobList:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: UpdateServiceJobList.main
events:
- http:
path: ServicesJobs/Update
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ServiceIndex:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ServiceIndex.main
events:
- http:
path: ServiceJobs/ServiceIndex
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
UpdateMyJob:
# Defines an HTTP API endpoint that calls the main function in update.js
# - path: url path is /notes/{id}
# - method: PUT request
handler: UpdateMyJob.main
events:
- http:
path: ServiceJobs/UpdateMyJob
method: put
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
PayInvoiceStripe:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: PayInvoiceStripe.main
events:
- http:
path: stripe/PayInvoice
method: post
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
StripeNewContractorAccount:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: StripeNewContractorAccount.main
events:
- http:
path: stripe/NewContractorAccount
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
serviceInfoPut:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: serviceInfoPut.main
events:
- http:
path: serviceInfo/post
method: post
cors: true
authorizer:
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
ListJobsForEdit:
# Defines an HTTP API endpoint that calls the main function in billing.js
# - path: url path is /billing
# - method: POST request
handler: ListJobsForEdit.main
events:
- http:
path: data/index/packageSelected
method: get
cors: true
authorizer: aws_iam
arn: aws:cognito-idp:us-east-2:433684495079:userpool/us-east-2_Q0sUvw4Qy
# Create our resources with separate CloudFormation templates
resources:
# API Gateway Errors
- ${file(resources/api-gateway-errors.yml)}
What you want is using CloudFormation Nested Stacks, they allow you to reference another CloudFormation stack using the AWS::CloudFormation::Stack resource type.
You can then provide parameters as an input to your nested stacks and retrieve their outputs once they are deployed, this is how you communicate between main and sub stacks.
Below is an example of a nested stack reference.
AWSTemplateFormatVersion: "2010-09-09"
Resources:
MyNestedStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: "https://s3.amazonaws.com/cloudformation-templates-us-east-2/EC2ChooseAMI.template"
Parameters:
Param1: "a-value"
Param2: "another-value"
Note that TemplateURL can point to S3 Bucket links or to a file on your filesystem. Once you want to deploy your stacks, they need to be packaged using the AWS CLI.
serverless-plugin-split-stacks is the plugin to be use.
Docs is here : serverless split stack
it will help you to split the stack into nested stacks, max limit is 20.

how to use scopes in Oauth2.0 to authorize user using Express Gateway(Microservice API Gateway)?

I did scopes with key-auth mechanism is perfectly working, but when i use scopes with Oauth2.0 mechanism, i am getting unauthorized error.
I did without scopes, the Oauth2.0 mechanism is working perfectly. Please suggest how to solve this problem?
Following is Gateway YAML configuration:
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
- host: 'localhost'
paths: ['/user', '/user/:id']
methods: ["GET"]
scopes: ["user"]
- host: 'localhost'
paths: ['/user', '/user/:id']
methods: ["PUT", "POST", "DELETE"]
scopes: ["admin"]
myApiRest:
host: 'localhost'
paths: '/posts'
serviceEndpoints:
jsonplaceholder:
url: 'http://localhost:8899'
restDummyService:
url: 'https://jsonplaceholder.typicode.com'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
- name: one
apiEndpoints:
- api
policies:
- oauth2:
#- basic-auth:
#- key-auth:
- proxy:
- action:
serviceEndpoint: jsonplaceholder
changeOrigin: true
- name: two
apiEndpoints:
- myApiRest
policies:
#- key-auth:
- proxy:
- action:
serviceEndpoint: restDummyService
changeOrigin: true

how to rename endpoints with express gateway?

i am trying to build an api that consists of different services and i want to everything to start with /api/ path. like the following below.
i want https://thirdparthy/comments to be routed as /api/comments on express gateway. what is the correct confirmation?
http:
port: 4000
admin:
port: 9876
hostname: localhost
apiEndpoints:
users:
host: localhost
paths: '/api/users'
comments:
host: localhost
paths: '/api/comments'
serviceEndpoints:
users:
url: 'https://jsonplaceholder.typicode.com/users'
comments:
url: 'https://jsonplaceholder.typicode.com/comments'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
users:
apiEndpoints:
- users
policies:
- proxy:
- action:
serviceEndpoint: users
prependPath: false
ignorePath: false
comments:
apiEndpoints:
- comments
policies:
- proxy:
- action:
serviceEndpoint: comments
prependPath: false
ignorePath: false
you can either use the rewrite policy to change the target url or simply configure the proxy policy accordingly:
- proxy:
- action:
serviceEndpoint: comments
prependPath: true
ignorePath: false
This should do the job.
Cheers,
V.