Hi!,
right now I’m implementing in my site a feature that should call an aws lambda through aws api gateway. The service use a federated identity pool (google) and I get my aws credentials using aws-sdk node module to connect to cognito. The first point (get aws credentials is done and works) but the second point haves me stuck. The thing is that I cannot use aws-amplify node module because wix does not support front end libraries, I cannot use aws-api-gateway-client because is not installed and I asked for installation 3 times but didn’t received a single answer. So I have 2 cards left, the first, to use the generated aws api gateway sdk for javascript or the second build my own http request using the wix third party services library. I’ve tried the first one but always get error codes, seems like js imported cannot be seen each other. This is my project structure:
The hole aws foder contains the generated sdk and aws.jsw uses it
I’ve followed this guidelines: https://docs.aws.amazon.com/en_en/apigateway/latest/developerguide/how-to-generate-sdk-javascript.html
My code:
import AWS from 'aws-sdk';
import 'backend/aws/lib/CryptoJS/rollups/hmac-sha256.js';
import 'backend/aws/lib/CryptoJS/rollups/sha256.js';
import 'backend/aws/lib/CryptoJS/components/hmac.js';
import 'backend/aws/lib/CryptoJS/components/enc-base64.js';
import 'backend/aws/lib/url-template/url-template.js';
import 'backend/aws/lib/apiGatewayCore/sigV4Client.js';
import 'backend/aws/lib/apiGatewayCore/apiGatewayClient.js';
import 'backend/aws/lib/apiGatewayCore/simpleHttpClient.js';
import 'backend/aws/lib/apiGatewayCore/utils.js';
import 'backend/aws/apigClient';
AWS.config.getCredentials((err) => {
if (err) {
console.log(err);
} else {
console.log('accessKeyId: ' + AWS.config.credentials.accessKeyId);
console.log('secretAccessKey: ' + AWS.config.credentials.secretAccessKey);
console.log('sessionToken: ' + AWS.config.credentials.sessionToken);
try {
console.log('apigClientFactory: ' + apigClientFactory.newClient());
} catch (e) {
console.error('error ---->' + e);
}
Always get error with my apigClient because apigClientFactory does not exist or newClient() is not a functions and it exists in apigClient.
var apigClientFactory = {};
apigClientFactory.newClient = function (config) {
var apigClient = { };
if(config === undefined) {
config = {
accessKey: '',
secretKey: '',
sessionToken: '',
region: '',
apiKey: undefined,
defaultContentType: 'application/json',
defaultAcceptType: 'application/json'
};
}
Has anyone an example code to invoke an api through api-gateway in wix?
Thanks.