Reputation: 606
Im brand new to AWS API Gateways and Lambda. I am trying to get the basic 'Hello from Lambda!' function to work.
I can sign in successfully as below:
const user = await Auth.signIn(email, password);
I get A token back which is correct as I tested it on the AWS API console and got the response
//token works as tested on AWS Console (API Tester)
const token = user2.signInUserSession.idToken.jwtToken
I assume that the request info is correct as the token is correct:
const requestInfo = {
headers: {
Authorization: token
}
}
I think the error is here as whenever I try to do anything with the 'Data' I don't get a response
const data = await API.get('API_NAME','/hello',requestInfo)
console.log('This is the Data: ',{ data } )
The Error I get in the try/catch Xcode is:
'API API_NAME does not exist'
any suggestions?
Error I get when I run Amplify Push:
Packaging lambda failed function failed with the error
Command failed with exit code 1: npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"16.8.6" from the root project
npm ERR! peer react@"^16.7.0" from @aws-amplify/[email protected]
npm ERR! node_modules/@aws-amplify/ui-react
npm ERR! @aws-amplify/ui-react@"^0.2.35" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.14.0" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^16.7.0" from @aws-amplify/[email protected]
npm ERR! node_modules/@aws-amplify/ui-react
npm ERR! @aws-amplify/ui-react@"^0.2.35" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/name/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/name/.npm/_logs/2021-02-02T09_36_01_091Z-debug.log
An error occurred during the push operation: Packaging lambda failed function failed with the error
Command failed with exit code 1: npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"16.8.6" from the root project
npm ERR! peer react@"^16.7.0" from @aws-amplify/[email protected]
npm ERR! node_modules/@aws-amplify/ui-react
npm ERR! @aws-amplify/ui-react@"^0.2.35" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.14.0" from [email protected]
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"^16.7.0" from @aws-amplify/[email protected]
npm ERR! node_modules/@aws-amplify/ui-react
npm ERR! @aws-amplify/ui-react@"^0.2.35" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/name/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/name/.npm/_logs/2021-02-02T09_36_01_091Z-debug.log
Upvotes: 0
Views: 701
Reputation: 561
As you can sign in successfully I suppose you've configured Amplify something like this specifying AWS poolId, clientId etc.
Similarly you've to do for APIs also like documented here
This is the format, suppose API name is account.
Amplify.configure({
Auth: { ... },
API: {
endpoints: [
{
name: 'account', // name of API like 'account', no '/'
endpoint: BASE_URL, // like 'https://api_name.com', don't put '/' at the end
region: 'us-east-1', // your region like 'us-east-1', 'ap-southeast-1' etc.
},
... // Other APIs
]
}
});
Then when you call the API this would be the format
const accountRes: AccountData = await API.get('account', '/account', requestInfo);
NOTE:- If API name is same but request type is different (GET, POST, PUT etc.) you don't need to do multiple entries, You can simply call respective method for the request API.get()
, API.post()
, API.put()
etc.
Upvotes: 1