anomalyinnovations / aws-api-gateway-cli-test Goto Github PK
View Code? Open in Web Editor NEWA simple CLI to test API Gateway endpoints with IAM authorization
License: MIT License
A simple CLI to test API Gateway endpoints with IAM authorization
License: MIT License
Firstly thanks for this tool! It is really useful for debugging issues.
And also, I spent a big chunk of time hunting down what was in the end a simple typo in my code for the name of the primary index column. One of the problems that slightly exacerbated it was that the HTTP status code returned was 500
but under the hood it's actually 400
. E.g.
Making API request
{
status: 500,
statusText: 'Internal Server Error',
data: {
status: false,
exception: '{"message":"The provided key element does not match the schema","code":"ValidationException","time":"2019-12-22T00:18:40.455Z","requestId":"CRVC9347J1AGP60CB6818OPN6JVV4KQNSO5AEMVJF66Q9AXXXXXX","statusCode":400,"retryable":false,"retryDelay":40.114206418810625}'
}
Digging into the code a bit to see where this mapping was, I noticed this CLI utility, as helpful as it is, seems to refer to this independent AWS client. I'm confused because that repository does have headers that say copyright Amazon; I can only presume this is a fork?
The issue is I don't think the 400
code should be mapped to a 500
code as this loses important information and is hard to trace back to official AWS docs when the code has been changed.
I've followed the tutorial at https://serverless-stack.com/chapters/test-the-apis.html . I'm sending all the parameters like so:
npx aws-api-gateway-cli-test \
--username='[email protected]' \
--password='Passw0rd!' \
--user-pool-id='eu-central-1_3XXXXXXXX' \
--app-client-id='kvxxxxxxxxxxigvkxxxx7a29' \
--cognito-region=‘eu-central-1' \
--identity-pool-id='eu-central-1:dxxxxxxx-28xx-4xxx-9xxx-cxxxxxxx6yyb' \
--invoke-url='https://lxxxxxxx49.execute-api.eu-central-1.amazonaws.com/prod' \
--api-gateway-region=‘eu-central-1' \
--path-template='/notes' \
--method='POST' \
--body='{"content":"hello world","attachment":"hello.jpg"}'
I've also tried without the prod
part after the url.
What I'm getting back is an (annoyingly) localized message in my language that says that required parameters identity-pool-id, invoke-url
are missing (and they aren't...).
How am I supposed to get past this point in the tutorial?
It appears that parameters passed into a GET method call with the --additional-params options are being ignored.
I'm able to successfully invoke DELETE, POST, PUT - so my cognito elements and the basic mechanisms are all good - and I can call GET with a path parameter, however anything I try to pass in as a querystring is ignored.
I've tried with escaped double quote JSON from windows i.e. --additional-params "{\"name\":\"value\"}"
as well as standard singe quoted JSON under Linux i.e. --additional-params '{"name":"value"}'
Note: the escaped quotes succeeds for JSON submitted in the --body
parameter under window.
Am I missing something obvious?
Thanks!
My AWS user pool is setup to use only phone numbers as the username. When I try to make an API call with this test cli I get the following message:
Authenticating with User Pool
Expected params.AuthParameters['USERNAME'] to be a string
I tried wrapping the username parameter in both single and double quotes. Same result.
npx aws-api-gateway-cli-test \
--username='15555555555' \
--password='Passw0rd!' \
...
with curl or other tools, I can easily feed the body from a file. It will be convenience for testing.
Could we have the same feature with aws-api-gateway-cli-tes
t? Such as:
--body="@/path/to/filename"
I did a try, but seems this feature is not ready currently.
Authenticating with User Pool
Getting temporary credentials
Making API request
undefined:1
@mocks/create.json
^
SyntaxError: Unexpected token @ in JSON at position 0
Reference: https://stackoverflow.com/questions/15912924/how-to-send-file-contents-as-body-entity-using-curl
Hey I'm trying to pass query parameters to the request. After looking up the aws amplify docs I've come up with this which unfortunately doesn't work.
--params "{\"queryStringParameters\":{\"offset\":\"10\"}}"
The event my lambda function recieves still has no query parameters
queryStringParameters: null,
Simply entering my api url into the browser and adding ?offset=10
works.
queryStringParameters: { offset: '10' },
So I guess my setup in serverless.yaml should be correct. And I'm entering the parameters wrong inside my console. I'm using cmd on windows btw.
Hi,
Right now I'm trying to test a deployment I made where I'm checking if one or more values are present on a specific field in any item. As such, this is what I'm sending:
--additional-params {\"queryParams\":{\"tag\":\"Rust\",\"tag\":\"nodejs\",\"op\":\"or\"}}
I can use the tag
parameter on the multiValueQueryStringParameters object, as such:
{
"queryStringParameters": {
"op": "or"
},
"multiValueQueryStringParameters": {
"tag": ["Rust","nodejs"]
},
"requestContext": {
"identity": {
"cognitoIdentityId": "admin123"
}
}
}
this logic is ok when I'm testing locally, but isn't working against dynamodb using the aws-api-gateway-cli-test, while there are values to be returned for such a query. What am I missing?
Gil
Not sure if this is a quirk in how I have my User Pool configured, but I was getting the following error when using the command provided in the serverless stack guide:
Command (with values removed):
apig-test --username='' --password='' --user-pool-id='' --app-client-id='' --cognito-region='us-east-1' --identity-pool-id='' --invoke-url='' --api-gateway-region='us-east-1' --path-template='/subscriptions' --method='POST' --body=""
Error:
Authenticating with User Pool
/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:31
throw err;
^
ReferenceError: navigator is not defined
at CognitoUser.authenticateUserInternal (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:343:19)
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:283:22
at Response.<anonymous> (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js:249:18)
at Request.<anonymous> (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:364:18)
at Request.callListeners (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/state_machine.js:26:10
I was able to get past the error and get the command to work by commenting out lines 343 and 604 in /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/amazon-cognito-identity-js/lib/CognitoUser.js that reference the navigator.
I'm following the tutorial at: https://serverless-stack.com/chapters/test-the-apis.html
I'm using node v8.9.4 and the latest packages as of 2/12/2018
I get this error:
apig-test --username [email protected] --password Passw0rd! --user-pool-id us-west-2_xZGqbyKso --app-client-id 4v4l8u687ku8b83lr9cd5irog6 --cognito-region us-west-2 --identity-pool-id us-east-1:b9f7dd39-1216-48bd-8580-132ca7fad875 --invoke-url https://hw9qpley70.execute-api.us-west-2.amazonaws.com/prod --api-gateway-region us-west-2 --path-template /notes --method POST --body "{\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
Authenticating with User Pool
C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\Client.js:54
fetch(this.endpoint, options).then(function (resp) {
^
ReferenceError: fetch is not defined
at Client.request (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\Client.js:54:5)
at C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:316:21
at AuthenticationHelper.getLargeAValue (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\AuthenticationHelper.js:85:7)
at CognitoUser.authenticateUserDefaultAuth (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:294:26)
at CognitoUser.authenticateUser (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\node_modules\amazon-cognito-identity-js\lib\CognitoUser.js:257:19)
at authenticate (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:106:15)
at Object.<anonymous> (C:\Users\Paul\AppData\Roaming\npm\node_modules\aws-api-gateway-cli-test\index.js:198:1)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
npx aws-api-gateway-cli-test
--username='REDACTED'
--password='REDACTED!'
--user-pool-id='REDACTED'
--app-client-id='REDACTED'
--cognito-region='us-east-1'
--identity-pool-id='REDACTED'
--invoke-url='REDACTED'
--api-gateway-region='us-east-1'
--path-template='/notes'
--method='POST'
--body='{"content":"hello world", "attachment":"hello.jpg"}'
Authenticating with User Pool
Getting temporary credentials
Making API request
/Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:172
if (argv.body.startsWith("@")) {
^TypeError: argv.body.startsWith is not a function
at makeRequest (/Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:172:17)
at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-api-gateway-cli-test/index.js:152:5
at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-sdk/lib/credentials.js:124:23
at /Users/REDACTED/.npm/_npx/ea84c6478cf14779/node_modules/aws-sdk/lib/credentials.js:212:15
at processTicksAndRejections (node:internal/process/task_queues:75:11)
npm ERR! code 1
npm ERR! path /Users/REDACTED/Serverless-Tutorial/notes-api
npm ERR! command failed
0 verbose cli [
0 verbose cli '/usr/local/bin/node',
0 verbose cli '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
0 verbose cli 'exec',
0 verbose cli '--',
0 verbose cli 'aws-api-gateway-cli-test',
0 verbose cli '[email protected]',
0 verbose cli '--password=Passw0rd!',
0 verbose cli '--user-pool-id=us-east-REDACTED',
0 verbose cli '--app-client-id=REDACTED',
0 verbose cli '--cognito-region=us-east-1',
0 verbose cli '--identity-pool-id=REDACTED',
0 verbose cli '--invoke-url=REDACTED',
0 verbose cli '--api-gateway-region=us-east-1',
0 verbose cli '--path-template=/notes',
0 verbose cli '--method=POST',
0 verbose cli '--body={"content":"hello world","attachment":"hello.jpg"}'
0 verbose cli ]
1 info using [email protected]
2 info using [email protected]
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 0ms
5 timing config:load:builtin Completed in 0ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:REDACTED/Serverless-Tutorial/notes-api/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/REDACTED.npmrc Completed in 1ms
11 timing config:load:user Completed in 1ms
12 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 7ms
19 verbose npm-session 3437d19e45fb8a34
20 timing npm:load Completed in 15ms
21 http fetch GET 304 https://registry.npmjs.org/aws-api-gateway-cli-test 196ms (from cache)
22 timing arborist:ctor Completed in 1ms
23 timing arborist:ctor Completed in 0ms
24 timing arborist:ctor Completed in 0ms
25 timing command:exec Completed in 3676ms
26 verbose stack Error: command failed
26 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
26 verbose stack at ChildProcess.emit (node:events:376:20)
26 verbose stack at maybeClose (node:internal/child_process:1063:16)
26 verbose stack at Process.ChildProcess._handle.onexit (node:internal/child_process:295:5)
27 verbose pkgid [email protected]
28 verbose cwd /Users/REDACTED/Serverless-Tutorial/notes-api
29 verbose Darwin 20.3.0
30 verbose argv "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "exec" "--" "aws-api-gateway-cli-test" "[email protected]" "--password=Passw0rd!" "--user-pool-id=us-east-REDACTED" "--app-client-id=REDACTED" "--cognito-region=us-east-1" "--identity-pool-id=us-east-1:REDACTED" "--invoke-url=REDACTED" "--api-gateway-region=us-east-1" "--path-template=/notes" "--method=POST" "--body={\"content\":\"hello world\",\"attachment\":\"hello.jpg\"}"
31 verbose node v15.5.0
32 verbose npm v7.3.0
33 error code 1
34 error path /Users/REDACTEDServerless-Tutorial/notes-api
35 error command failed
36 error command sh -c apig-test [email protected] --password=Passw0rd! --user-pool-id=REDACTED --app-client-id=REDACTED --cognito-region=us-east-1 --identity-pool-id=us-east-1:REDACTED --invoke-url=REDACTED --api-gateway-region=us-east-1 --path-template=/notes --method=POST --body={"content":"hello world","attachment":"hello.jpg"}
37 verbose exit 1
If the cognito user being authenticated is signing in for the first time, they might need to set a new password as well as any other required attributes. I don't think there's a way of pausing execution to accept more args with yargs (maybe with Vorpal), but here's the function signature for newPasswordRequired to be added to the callback object in cognitoUser.authenticateUser(authenticationDetails, callbacks)
newPasswordRequired: function (userAttributes, requiredAttributes) {
// User was signed up by an admin and must provide new
// password and required attributes, if any, to complete
// authentication.
// userAttributes: object, which is the user's current profile. It will list all attributes that are associated with the user.
// Required attributes according to schema, which don’t have any values yet, will have blank values.
// requiredAttributes: list of attributes that must be set by the user along with new password to complete the sign-in.
// Get these details and call
// newPassword: password that user has given
// attributesData: object with key as attribute name and value that the user has given.
cognitoUser.completeNewPasswordChallenge({NEW_PASSWORD}, {REQUIRED_ATTRIBUTES}, this)
}
Hello guys !
Little issue while using the aws-api-gateway-cli-test, but I'm pretty new to AWS, I am just following a tutorial so far, so apologies in advance if this issue isn't one.. But I searched the web for a similar error related to the test cli and didn't find one..
So here it is, I tried both methods :
npx aws-api-gateway-cli-test \
--username=MY_USER_NAME \
--password=MY_PASSWORD \
--user-pool-id=MY_POOL_REGION \
--app-client-id=MY_APP_CLIENT_ID \
--cognito-region=MY_COGNITO_REGION \
--identity-pool-id=MY_POOL_ID \
--invoke-url=MY_GATEWAY_URL \
--api-gateway-region=MY_GATEWAY_REGION \
--path-template=/notes \
--method=POST \
--body={"content":"hello world","attachment":"hello.jpg"}
and
npm i -g aws-api-gateway-cli-test
apig-test \
--username=MY_USER_NAME \
--password=MY_PASSWORD \
--user-pool-id=MY_POOL_REGION \
--app-client-id=MY_APP_CLIENT_ID \
--cognito-region=MY_COGNITO_REGION \
--identity-pool-id=MY_POOL_ID \
--invoke-url=MY_GATEWAY_URL \
--api-gateway-region=MY_GATEWAY_REGION \
--path-template=/notes \
--method=POST \
--body={"content":"hello world","attachment":"hello.jpg"}
Both are returning the same output for me :
Authenticating with User Pool
Getting temporary credentials
Making API request
/usr/local/lib/node_modules/aws-api-gateway-cli-test/index.js:172
if (argv.body.startsWith("@")) {
^
TypeError: argv.body.startsWith is not a function
at makeRequest (/usr/local/lib/node_modules/aws-api-gateway-cli-test/index.js:172:17)
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/index.js:152:5
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/credentials.js:124:23
at /usr/local/lib/node_modules/aws-api-gateway-cli-test/node_modules/aws-sdk/lib/credentials.js:212:15
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Thank you in advance, and sorry again if this id an error on my side
Is there anyway for the CLI to output the entire response including deeply nested objects?
Now the output becomes, for example: requestContext: [Object]
On Windows 11
using GitBash
MINGW64
(the command line tool bundled with Git
for Windows, downloaded from from https://git-scm.com/downloads)
When I try to run the
npx aws-api-gateway-cli-test [other flags] --invoke-url='https://**********.execute-api.eu-west-2.amazonaws.com'
I receive:
Getting temporary credentials
Making API request
getaddrinfo ENOTFOUND uxh91gk4ta.execute-api.eu-west-2.amazonaws.comc
^ ℹ️ Note the additional "c" at the end of the url that is not present in the original --invoke-url string
This seems to be a bug in how MINGW64 translates the url.. hence the stray "c" character?
But I would like to know if other's experience this?
When I run the above command on the same machine
but using Windows Subsystem for Linux Ubuntu
it is successful ✅
When I run the above command on the same machine
but using Windows Command Prompt
(but adhering to Windows Command Prompt formatting) it is successful ✅
When I run the above command on a different machine
with Linux
the it is successful ✅
All 3 give a successful response:
Getting temporary credentials
Making API request
{
status: 200,
statusText: 'OK',
data: {
userId: 'eu-west-2:************************',
noteId: '************************',
content: 'hello world',
attachment: 'hello.jpg',
createdAt: 1702480927787
}
}
When run apig-test
, get below error.
Authenticating with User Pool
Getting temporary credentials
Making API request
^@write EPROTO 4480091584:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:
I have upgraded openssl
to latest.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.