Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
Which Category is your question related to?
Amplify Function
Amplify CLI Version
You can use amplify -v
to check the amplify cli version on your system
3.16.0
What AWS Services are you utilizing?
Appsync
Provide additional details e.g. code snippets
I have managed to call appsync endpoint using the following code
schema.graphql
type AnomalyEvent @model
@auth(rules: [
{allow: owner},
{allow: private, provider:iam}
]) {
id: ID!
received_on: AWSDateTime!
value1: Int!
value2: Float
}
lambda function
const appsync = require('aws-appsync');
const gql = require('graphql-tag');
require('cross-fetch/polyfill');
const url = process.env.API_FAMILYPWAFRONTENDGRAPHQL_GRAPHQLAPIENDPOINTOUTPUT;
const graphqlClient = new appsync.AWSAppSyncClient(
{
url: url,
region: process.env.REGION,
auth: {
type: 'AWS_IAM',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN
}
},
disableOffline: true,
},
{
defaultOptions: {
query: {
fetchPolicy: 'network-only',
errorPolicy: 'all',
},
},
}
);
..call graphql code
{
"name": "callAppsyncExample",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"aws-appsync": "3.0.2",
"cross-fetch": "3.0.4",
"graphql-tag": "2.10.1"
}
}
Problem is, the packaged lambda is around 100Mb and it is detrimental to development since it takes too long to push amplify changes.
I can think of reducing the load time one of two ways:
1- use layers in Lambda
2- using light weight graphql client such as graphql-request
I do not how to do the first one in Amplify and if you think this is better option then please let me know how I can do it.
I tried the second option and started building lambda function as follows
const { GraphQLClient } = require('graphql-request');
const aws4 = require('aws4')
var apiAngularpwapostoneGraphQLAPIEndpointOutput = process.env.API_FAMILYPWAFRONTENDGRAPHQL_GRAPHQLAPIENDPOINTOUTPUT
exports.handler = async function (event) { //eslint-disable-line
console.log(apiAngularpwapostoneGraphQLAPIEndpointOutput)
const opts = {host:"appsync.us-east-1.amazonaws.com"}
aws4.sign(opts, {accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey:
process.env.AWS_SECRET_ACCESS_KEY, sessionToken:
process.env.AWS_SESSION_TOKEN})
console.log(opts)
const graphQLClient = new GraphQLClient(apiAngularpwapostoneGraphQLAPIEndpointOutput, {
headers:opts.headers
});
call mutation...
package.json
{
"name": "leanLambdaAppsyncCall",
"version": "2.0.0",
"description": "Lambda function generated by Amplify",
"main": "index.js",
"license": "Apache-2.0",
"dependencies": {
"graphql-request": "1.8.2",
"aws4": "1.8.0"
}
}
The idea is to generate AWS4 signature using aws4 library and use it to make call with graphql-request library. These libraries have under 1Mb footprint but I get the following error every time I try
Invoke Error {"errorType":"Error","errorMessage":"GraphQL Error (Code: 403): {\"response\":{\"message\":\"Forbidden\",\"status\":403}
My headers look like
{ Host: 'appsync.us-east-1.amazonaws.com',
'X-Amz-Security-Token':
'IQoJb3JpZ2luX2VjEKz//////////wEaCXVzLWVhc3QtMSJGMEQCIG2LE/qIBcc157ZyxEPCiG/iBN2wOadaipDiblraxGsdAiB/QPxkL9vrOPPU5o4nHaXK5YNPTS5vZhx1j5QPIzy3BiroAQjV//////////8BEAAaDDEyMDM0ODk1MjQzNCIMkuq2rrei+oU5GxmzKrwBlgg1afns2yLCAkbkEiCN1q5YaKaFz8bhDE4zfD7I1Fi9j90Ci3MzL0Z/gDlCx9c6PZCiwQPsOjXELEDaJbmGoUiAJdNCm7f702MkKu+w9FizD5cuKFet2mAodZqt/NQbHWMM5Xrt/jX31Ul7Z0EutCgB7lQ7ZLaGZTzKdolvoKdU65XIOXGTYd05KY3+0y8InUA4XmNIiC9L1shIShxJodzM/KZdRq4GCztkivQ7I9T/3kpEyhfMRw1Nhukwh8rU7gU64QHHlfFCJZldWtZDL45b+jMXwvC6wvnYELUM8aQCBrEKBO7KT8LdL5Fi9DgUlOiTtvlnwDdJJVAMXsABBeYU9OlGZETlQCItBiVceD9U8hWtQsPYMuKjZ9CdV6dZi17ZolVE4f++tqc1qe5qx43ZdsdrAjNTtsZcfvLrvsWDwYqs41rieX/XkwhKQBpJVCb2VPxYdnGCaSin5QHyvmXYuTq5fTELEXYLeTOrKTXRP5/LfYZK6xyKNNPiLm3wBOMZoLv1w9fopoHVz1UO6lF7TeEgN/bqBCKJOQA92ONQXjcTOFM=',
'X-Amz-Date': '20191120T113741Z',
Authorization:
'AWS4-HMAC-SHA256 Credential=ASIARYBK3I5ZBCJT7FFP/20191120/us-east-1/appsync/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=9f130592054efd5a738e50acbccc7628b65dcab35ddf7f5c0de61e1c5a7b1a43' },
path: '/' }
I would appreciate if you can provide a solution one or the other way. Thanks
@daghanacay Can you work on the formatting a bit? It will help us decipher the issue you are facing.
@ammarkarachi I have formatted the code. can you please take a look at it now. This is something that will improve the usability of amplify and appsync
@daghanacay Thank you!
@ammarkarachi is there any development on this? can you please give an indication if you ever will look at this?
@daghanacay We'll definitely be looking into adding support for Lambda layers in the next couple of months.
+1
Hi everyone! We're actively looking into this now. We don't have an ETA just yet but we'll keep this thread updated!
+1
+1
+1
Closing since Amplify CLI supports Lambda layers. The latest update to Lambda layers was released in 4.29.0.
Great news. Thanks
Get Outlook for Androidhttps://aka.ms/ghei36
From: John Hockett notifications@github.com
Sent: Friday, September 4, 2020 8:50:01 AM
To: aws-amplify/amplify-cli amplify-cli@noreply.github.com
Cc: daghanacay daghanacay@gmail.com; Mention mention@noreply.github.com
Subject: Re: [aws-amplify/amplify-cli] Lambda layers support (#2798)
Closing since Amplify CLI supports Lambda layers. The latest update to Lambda layers was released in 4.29.0.
https://docs.amplify.aws/cli/function/layers
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/aws-amplify/amplify-cli/issues/2798#issuecomment-686802646, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABV2FLQSCOVDPA62LAVXT2TSEAMRTANCNFSM4JQABOYQ.
Most helpful comment
Hi everyone! We're actively looking into this now. We don't have an ETA just yet but we'll keep this thread updated!