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 ?
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.
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 ).
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.
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"), {...})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With