How to provide blob of graphql schema to aws appsync api? - aws-cli

I am trying to use aws appsync api (StartSchemaCreation) to create schema of a new graphql api with the schema of an existing graphql api, that I dumped with GetIntrospectionSchema api of aws appsync. But the --definition param of StartSchemaCreation requires me to provide a blob of graphql schema to create in the new api. I have my graphql schema in .json and .graphql files, but I cannot use them directly, as it gives error "Failed to parse schema document - ensure it's a valid SDL-formatted document."
I need help understanding how can I pass my graphql schema through --definition param of start-schema-creation.
I am using aws-cli StartSchemaCreation.

You can use
aws appsync start-schema-creation \
--api-id <your-api-id> \
--definition file://<file-path>

It looks like the definition parameter is expected to be a base64 encoded string of the schema. This doesn't appear to be documented anywhere in the AWS CLI docs, but I found this tidbit here
Which led me to try this command which worked:
aws appsync start-schema-creation --api-id <your-api-id> --definition $(base64 /path/to/schema.graphql)

Related

How to set a profile on an aws client

I'm trying to create an AWS client for IOT following this article: How can I publish to a MQTT topic in a Amazon AWS Lambda function?
client = boto3.client('iot-data', region_name='us-east-1')
However I need to set a profile so that boto3 picks the correct credentials from my ~/.aws/credentials file.
The articles that describe how to do this (How to choose an AWS profile when using boto3 to connect to CloudFront) use Session instead of creating a client. However iot-data is not a "resource" that you can get from Session.
boto_session = boto3.Session(profile_name='my-profile')
boto_client = boto_session.resource('iot-data', region_name='us-west-1')
When I try the above I get the error:
Consider using a boto3.client('iot-data') instead of a resource for 'iot-data'
And we've achieved full catch-22 status. How can I get an appropriate IOT client using an AWS profile?
IoTDataPlane does not have resource. You can only use client with the IoTDataPlane:
boto_session.client('iot-data', region_name='us-west-1')

How can I integrate a credential json file with GCP bigquery with nodejs?

I have a file type of json. It is a credential file. I want to integrate with GCP bigquery and access to GCP bigquery using this credential file with Nodejs.
How can I do that?
How can integrate with GCP bigquery using credential file in nodejs?
How can I test the result of integration to test integration is valid or not?
You probably want the keyFilename attribute, unless I've misunderstood your question.
This GCP doc talks about authenticating using a service account key file.
So if your credentials file lived in /var/my_credentials.json (dumb path but whatever), your Node.js code would look something like this:
const {BigQuery} = require('#google-cloud/bigquery');
const options = {
keyFilename: '/var/my_credentials.json',
projectId: 'my_project',
};
const bigquery = new BigQuery(options);
Also consider: keep the contents of that credentials file in Google Secret Manager and use gcloud secrets versions access latest, dumping the output into a temporary json file local to the script, then remove the temporary json file after it's no longer needed by the script. No need to have credentials floating around on servers.

How to pass nested query string parameter to AWS Lambda from Amazon API Gateway

In this question How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway
it shows how to map query string params to AWS lambda using API gateway. But, i want to pass a querystring inside a variable to lambda
For example:
/api/index&sample=index.php <--- I want this to store in 'url'
www.sample.com/prod?url=/api/index&sample=index.php <--- Like this
but 'url' only returns /api/index
sample=index.php is treated as another variable.
I used application/json on mapping templates
{
"url": "$input.params('url')"
}
How do you do this. Please help thanks in advance

AWS Lambda gateway API gives error message

I have created one API endpoint for lambda function, as - https://XXXXXXXXX.execute-api.us-east-1.amazonaws.com/XXXX/XXXXXXXXXXXX/ which is GET method.
While calling that endpoint from postman it is giving me
{
"message": "'XXXXXXXXX3LPDGPBF33Q:XXXXXXXXXXBLh219REWwTsNMyyyfbucW8MuM7' not a valid key=value pair (missing equal-sign) in Authorization header: 'AWS XXXXXXXXX3LPDGPBF33Q:XXXXXXXXXXBLh219REWwTsNMyyyfbucW8MuM7'."
}
This is a screenshot of the Amazon Lambda Upload Site: http://i.stack.imgur.com/mwJ3w.png
I have Access Key Id & Secret Access Key for IAM user. I used it all but no luck. Can anyone suggest tweak about this.
If you're using the latest version of Postman, you can generate the SigV4 signature automatically. The region should correspond to your API region (i.e. "us-east-1") and the service name should be "execute-api"
This is not a solution but it has helped me more than once:
Double-check that you are actually hitting an existing endpoint! Especially if you're working with AWS. AWS will return this error if you don't have the correct handler set up in your Lambda or if your API Gateway is not configured to serve this resource/verb/etc.

Can't access Glacier using AWS CLI

I'm trying to access AWS Glacier (from the command line on Ubuntu 14.04) using something like:
aws glacier list-vaults -
rather than
aws glacier list-vaults --account-id 123456789
The documentation suggests that this should be possible:
You can specify either the AWS Account ID or optionally a '-', in
which case Amazon Glacier uses the AWS Account ID associated with the
credentials used to sign the request.
Unless "credentials used to sign the request" means that I have to explicitly include credentials in the command, rather than rely on my .aws/credentials file, I would expect this to work. Instead, I get:
aws: error: argument --account-id is required
Does anyone have any idea how to solve this?
The - is supposed to be passed as the value of --account-id, so like
aws glacier list-vaults --account-id -
--account-id is in fact a required option.
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/glacier/list-vaults.html
Says that "--account-id" is a required parameter for the glacier section of the full aws api. A little wierd, but documented. So yay.

Resources