I have been trying to add time-based scheduling via AWS SDK. Here is sample code snippet
const {ElasticBeanstalkClient ,
UpdateConfigurationTemplateCommand } = require('#aws-sdk/client-elastic-beanstalk');
const abortEnvironmentUpdateCommand = new
UpdateConfigurationTemplateCommand({ApplicationName:'Admin Portal',EnvironmentName:'xxxx-xxxx-v2',
"OptionSettings.member.1.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.1.OptionName": "MinSize",
"OptionSettings.member.1.Value": "1",
"Operation": "UpdateConfigurationTemplate",
"OptionSettings.member.2.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.2.OptionName": "MaxSize",
"OptionSettings.member.2.Value": "1",
"OptionSettings.member.3.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.3.OptionName": "DesiredCapacity",
"OptionSettings.member.3.Value": "1",
"OptionSettings.member.4.Namespace": "aws:autoscaling:scheduledaction",
"OptionSettings.member.4.OptionName": "StartTime",
"OptionSettings.member.4.Value": "2022-08-18T00:00:00Z",
"TemplateName":'xxxxxTestConfiguration'});
elasticbeanstalktemp
.send(abortEnvironmentUpdateCommand)
.then(data => {
console.log("Data",data);
// do something
})
.catch(error => {
console.log("Error",error);
// error handling
});
In response, I am getting 200 status codes but when I am applying updated configuration to the environment, it doesn't add time-based scheduling action.
Can anyone help me pointing what I am doing wrong ?
Related
I have a bunch of forms that input data into my firebase database using a express API and cloud functions.
I have one main issue - I'm getting a error on trying to test my API when inputting the form data.
The secondary issue is more, is there a cleaner way to take the inputted form data to the firebase than how I am currently doing it.
This is the code to create a new workflow (which is the data outputed from the forms)
(this is the required code from the route file)
const {getAllWorkflows,
postOneWorkflow} = require('./handlers/workflow');
// Workflow Routes
app.get('/Workflows', getAllWorkflows);
app.post('/Workflow', postOneWorkflow);
And this is the request code from a handler file
exports.postOneWorkflow = (req, res) => {
const newWorkflow = {
completed: req.body.completed,
currentStep: req.body.currentStep,
createdAt: new Date().toISOString(),
Reason: req.body.Reason,
breach: req.body.breach,
cauInd: req.body.cauInd,
cauOth: req.body.cauOth,
cauWea: req.body.cauWea,
claimEoT: req.body.claimEoT,
dateAware: req.body.dateAware,
dateEoTClaim: req.body.dateEoTClaim,
daysClaimed: req.body.daysClaimed,
dec: req.body.dec,
delayRespon: req.body.delayRespon,
descB: req.body.descB,
descCau: req.body.descCau,
descExt: req.body.descExt,
event: req.body.event,
eviCause: req.body.eviCause,
eviExtent: req.body.eviExtent,
ifGranDay: req.body.ifGranDay,
notice: req.body.notice,
proMitPro: req.body.proMitPro,
proResPro: req.body.proResPro,
recWri: req.body.recWri,
stepsMit: req.body.stepsMit,
stepsPre: req.body.stepsPre
};
db.collection("Workflow")
.add(newWorkflow)
.then(doc => {
const resWorkflow = newWorkflow;
resWorkflow.WorkflowId = doc.id;
res.json(resWorkflow);
})
.catch(err => {
res.status(500).json({ error: "something went wrong" });
console.error(err);
});
};
I'm currently receiving an error of
SyntaxError: Unexpected token c in JSON at position 10
when inputting json using postman to the workflow post route,
{
completed: "False",
currentStep: 1,
claimEoT: "True",
event: "True",
notice: "True",
recWri: "True",
dateEotClaim: "",
dateAware: "",
eviCause: "",
descCau : "",
eviExtent : "True",
descExt : "",
daysClaimed : 5,
delayRespon : "True",
proResPro : 1,
stepsPre : "True",
proPrePro : 1,
stepsMit: "True",
proMitPro : 10 ,
breach : "True",
descB : "describe",
cauInd : "True",
cauWea : "True",
cauOth : "True",
dec : "True",
ifGranDay : 5,
Reason : "I AM THE SENATE"
}
Not 100% sure why as it seems like my formatting is fine?
With creating the query - I wonder if there is a more efficient way of doing this other than writing an ungodly amount of code for the queries.
The point is I need to be able to query the different collections and edit them, but I feel like a query that just took in what it was told, and sent it through to this database, without having to specify the specific "completed", or "Reason",would be ideal.
Your postman JSON is invalid. The keys are also supposed to be enclosed in quotes.
{
"completed": "False",
"currentStep": 1,
...
}
You can just create the newWorkflow object from req.body!
const newWorkflow = req.body;
newWorkflow.createdAt = new Date().toISOString();
When I use the .create(item) method to do an INSERT from the client (within the browser) I see 1 call via websocket or REST go to feathersjs. I see one request go into Feathersjs. For an unknown reason I see 2 rows created in MySql and 2 lines in the log that say: {"message":"after: name_of_service - Method: create","level":"info"}
Using sequelize 4.42.0 and feathers-sequelize 6.0.1
I do not have the issue when running create() from within the server code, only from client.
I found https://github.com/feathersjs-ecosystem/feathers-rethinkdb/issues/80 that looked simular but is for a different DB and the explanation did not fit with MySql.
I switched to MariaDB for other reasons but obviously nothing changed.
I was using FeathersJS v3.x and upgrading to v4.x to see if that would fix it. Nope. As I work around I have been making my own insert methods but it would be nice to use the built in ones.
I tried switching between REST and websocket.
My Hooks:
const { authenticate } = require('#feathersjs/authentication').hooks;
module.exports = {
before: {
all: [ ], // authenticate('jwt') normally use, but deactivated to debug
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
Service:
const createService = require('feathers-sequelize');
const createModel = require('../../models/name_of_service.model');
const hooks = require('./name_of_service.hooks');
module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');
const options = {
Model,
paginate: {
default: 100,
max: 2000
}
};
app.use('/name_of_service', createService(options));
const service = app.service('name_of_service');
service.hooks(hooks);
};
I expected it to insert 1 row in MySql table. But got 2. I expected one row in the log for the after hook, but see 2. This has been happening for a couple of months and was thinking, hey, maybe I am not the only one.
Thank you everyone for your help. I found the issue.
I fixed my rooky mistake by changing:
app.configure(socketio());
app.configure(socketio(function(io) {io.sockets.setMaxListeners(555);}));
To:
app.configure(socketio(function(io) {io.sockets.setMaxListeners(555);}));
I don't know how to ask this question, but i have a react redux project that show some products with some functionality like filtering and sorting..etc
I have created a json file that represents the data and i need to mimic receiving this data from a server that i have already created using express as if i receive data from a remote server.
I have no knowledge about backend so i am confused how can i do that, i feel there is a lost piece so i can not make a connection between data and server and the project.
What is the key to achieve that ??
As I commented above either use myjson or you can use json-server package.
In your project folder, you just need to create a json file ex. local-api.json
ex :
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
and you can run it like this :
json-server --watch local-api.json
Note: example is taken from there to make you understand. You can explore more about this package in their GitHub website
For more reference go there GitHub site : here
Express server example
const express = require('express')
const app = express()
const port = 5000
app.get('/', (req, res) => res.json({"hello":"world"})) //add your data
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
run this file using node index.js and make sure you install express(
npm install express --save)
And then you can fetch in your component like this :
componentDidMount(){
axios.get("http://localhost:5000").then(data => //your logic)
}
I want to make the JSON you see in the script below get pulled from an API instead of being in the script itself. I can't figure it out for the life of me. I'm fairly new to TypeScript, so forgive me if I sound like a noob :)
export class FaqFakeDb
{
public static data = [
{
"id": "1",
"question": "test1",
"answer": "test1"
},
{
"id": "2",
"question": "test2",
"answer": "test2"
},
{
"id": "3",
"question": "test3",
"answer": "test3"
}
]
}
I have tried everything and cannot seem to get it working. Any help would me much appreciated.
p.s. Anyone looking to answer could you please include my code or give the full script because I'm not too familiar with the structure of Typescript yet, thanks.
You can code an API really quickly using Express. Here's a quick and simple way to setup one that will serve your data:
Navigate to /where/you/want/your/server/to/be (chose a directory that will host an NPM project)
Initiate an NPM project: npm init -y
Install express: npm install express
In ./data.json, paste your data ([{"id": "1", "question":...)
In server.js, code a server that will serve your data over HTTP:
const express = require('express');
// create an express server
const app = express();
// serves the 'data.json' at the path '/data'
app.get('/data', (req, res) => {
res.sendFile(`${__dirname}/data.json`);
});
// launches the server on localhost, port 8080
app.listen(8080, () => {
console.log('Server listening on http://localhost:8080');
})
And that's it! You can navigate to a browser at localhost:8080/data and you'll see your data being returned. Alternatively, you can programmatically fetch your data using JavaScript:
fetch('http://localhost:8080/data')
.then(resp => resp.json()) // parse the JSON data
.then(data => console.log('received data:', data)); // logs the data
You would need to set up a server with a route that would then serve that JSON in response to a GET request.
If you want to practice, I recommend using public APIs that already have "fake" data.
www.swapi.co is one example, returning data related to StarWars.
I can't seem to find any documentation on how to actually use the postabck feature. Does it call functions on the server? What does ti do with the pasees value?
%[Button label here](postback:PAYLOAD_HERE) // What is the payload?
The payload is actually whatever you want!
Postback buttons can be used as triggers to your webhook. When a user taps on your postback button, a payload will be sent to your webhook with the following data:
{
"trigger": "postback",
"postbacks":[{
...
"action": {
"_id": "571530ee4fae94c32b78b170",
"type": "postback",
"text": "Read more",
"payload": "YOUR_PAYLOAD_HERE" // <---- your payload!
}
}],
...
}
For complete payload see this reference: http://docs.smooch.io/rest/#webhooks-payload
On your side, you could have automated messages, event scheduling or anything you want.
A simple payload could be TELL_ME_JOKE and on your backend, you could fetch your database for a joke, then send a message through the Smooch API to reply back.
Another payload could be RESERVE_MONDAY. When the user taps that button, your webhook receives RESERVE_MONDAY. Then you could use that value to know what to do next (call into your application to reserve that time slot).
Here's a simple Node.js implementation:
const express = require('express');
const SmoochCore = require('smooch-core');
const smoochApi = new SmoochCore({
keyId: 'some-key',
secret: 'some-secret',
scope: 'app'
});
express.Router().post('/smooch/webhooks', (req, res) => {
const smoochPayload = req.body.postbacks[0].action.payload;
const userId = req.body.appUser._id;
if (smoochPayload === 'TELL_ME_JOKE') {
smoochApi.conversations.sendMessage(userId, {
text: 'A cow walks into a bar...',
role: 'appMaker'
});
} else if (smoochPayload === 'RESERVE_MONDAY') {
CalendarController.reserve(userId, 'monday');
}
res.end();
});
Using the payload also allows you to use different button labels, but keep the same payload (ie. different translations).
Note: it could be anything even JSON if you want!
I hope this can help you!
The payload is what you want your bot to return. I'm not sure if my way of describing it is the best since I'm new at this. Think of it this way - If you have a button labeled %[Yes](postback:YES), then when the user clicks on the button that says yes, it will be just like they typed the word "yes."