Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ref(id) of my last instance created

Tags:

faunadb

I don't know how to simply get the ref(id) of my last instance created with faunadb. I need to put it in an url.

I use this to create my instance:

/* code from functions/todos-create.js */
import faunadb from 'faunadb' /* Import faunaDB sdk */
/* configure faunaDB Client with our secret */
const q = faunadb.query
const client = new faunadb.Client({
  secret: process.env.FAUNADB_SECRET
})

/* export our lambda function as named "handler" export */
exports.handler = (event, context, callback) => {
  /* parse the string body into a useable JS object */


  const eventBody = JSON.stringify(event.body)
  const data = JSON.parse(eventBody)
  const mission = {
    data: JSON.parse(data)
  }
  // {"title":"What I had for breakfast ..","completed":true}
  /* construct the fauna query */
  return client.query(q.Create(q.Ref("classes/missions"), mission))
  .then((response) => {
    console.log("success", response)
    /* Success! return the response with statusCode 200 */
    return callback(null, {
      statusCode: 200,
      body: JSON.stringify(response)
    })
  }).catch((error) => {
    console.log("error", error)
    /* Error! return the error with statusCode 400 */
    return callback(null, {
      statusCode: 400,
      body: JSON.stringify(error)
    })
  })
}

I begin to dev, and I need to do this simply with faunadb, can you help me please ?

like image 413
Math73100 Avatar asked Jun 12 '19 12:06

Math73100


People also ask

How do I find my EC2 instance history?

Open the CloudTrail console, and then choose Event history from the navigation pane. For Filter, choose Resource name from the dropdown menu. For Enter resource name, enter the instance ID. (Optional) For Time range, select a time range.

How do I find my EC2 instance IMDS?

If you want to determine it from the EC2 instance, you can just try sending a request to http://169.254.169.254/ and see what the status code is. The 401 status code means Unauthorized. This server does not require IMDSv2 ( HttpTokens is optional ).

What is AWS instance ID?

Your Amazon Connect instance ID is the 36-character string at the end of your instance's Amazon Resource Name (ARN). To see your instance's ARN, follow the instructions in Find your Amazon Connect instance ID/ARN.


1 Answers

Instance creation returns a ref, as along with other instance metadata and the user supplied instance data. This means we can compose a select with the create to pull the data out that you require. Using the shell syntax:

Select("ref", Create(Class("missions"), {...})

will yield the ref. Of course if you'd like just the id part of the ref you can drill in further:

Select(["ref", "id"], Create(Class("missions"), {...})
like image 68
benjumanji Avatar answered Oct 07 '22 14:10

benjumanji