InvalidInput: Invalid request on AWS Route 53 - javascript

I am trying to set resource records in AWS route 53 via the SDK and I am getting an Invalid Request error(InvalidInput). Can you double check my params to make sure that I have them set correctly?
function testw () {
var params = {
ChangeBatch: {
Changes: [
{
Action: 'CREATE',
ResourceRecordSet: {
Name: 'example.com',
Type: 'A',
AliasTarget: {
DNSName: 's3-website-us-east-1.amazonaws.com',
EvaluateTargetHealth: false,
HostedZoneId: 'Z1YU6G6WEXAMP'
},
}
},
],
Comment: 'This is a test and it should be working.'
},
HostedZoneId: 'Z1YU6G6WEXAMP'
};
route53.changeResourceRecordSets(params, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
Thanks for any help!!

Can you try removing the TTL? When you use aliases, you do not specify the TTL as Route 53 will use the target's TTL. Also, per the documentation, your alias target zone id should be Z3AQBSTGFYJSTF.

Related

Meanjs Forbidden Error

I am a new bee in AngularJs,below is the policy code created by Meanjs yo generator ,for learning purpose have created a library management system ,The problem what i am facing is when i am testing my server code i.e the API through browser URL...I am getting the result for
http://localhost:3000/api/searchbooks/bookname/davincicode as JSON Object
but for below url it's giving me {message: 'User is not authorized'}
http://localhost:3000/api/searchbooks/bookname/davincicode/bookName
exports.invokeRolesPolicies = function () {
acl.allow([
{
roles: ['user'],
allows: [{
resources: '/api/searchbooks',
permissions: ['get']
}, {
resources: '/api/searchbooks/bookname/:searchbookName',
permissions: ['get']
}]
},
{
roles: ['user'],
allows: [{
resources: '/api/searchbooks/bookname',
permissions: ['get']
}, {
resources: '/api/searchbooks/bookname/:searchbookName/:action',
permissions: ['get']
}]
}
])};
exports.isAllowed = function (req, res, next) {
var roles = (req.user) ? req.user.roles : ['guest'];
// If an Searchbook is being processed and the current user created it then allow any manipulation
if (req.searchbook && req.user && req.searchbook.user && req.searchbook.user.id === req.user.id) {
return next();
}
// Check for user roles
acl.areAnyRolesAllowed(roles, req.route.path, req.method.toLowerCase(), function (err, isAllowed) {
if (err) {
// An authorization error occurred
return res.status(500).send('Unexpected authorization error');
} else {
if (isAllowed) {
// Access granted! Invoke next middleware
return next();
} else {
return res.status(403).json({
message: 'User is not authorized'
});
}
}
});
};
I checked my role it's going as user only ,unable to find so specific question elsewhere pls help or provide some pointers.
I have got the issue made mistake in routing part :
app.route('/api/searchbooks/bookname/:searchbookName/:actionValue').all(searchbooksPolicy.isAllowed)
.get(searchbooks.read)
Here in policy url its action and i have to give actionValue as the parameter name.
so passing incorrect parameter name was an issue..

How to get the revision history of user from Rally using Node js scripting

My requirement is to get the exact date/time when a user gets disabled.
To achieve this, I need to query for the line 'user set to INACTIVE' in the Revision History to find the date the user was switched from enabled to disabled.
How can I get the revision history using node js ?
I tried below code, but its not working as Rally support team mentioned that its older code and i have to try with v2.0.
Can somebody help me to achieve my requirement ?
var revisions = story.RevisionHistory.Revisions;
revisions.sort(byRevisionNumber);
var story_was_blocked = false;
// it doesn't matter how many revs have been in BLOCKED state, presence of one is sufficient
for (var rix = 0; rix < revisions.length && story_was_blocked === false; rix++) {
var rev = revisions[rix];
if (rev.Description.indexOf("BLOCKED changed from ") >= 0) {
story_was_blocked = true;
}
}
Here's a brief example of how this might be accomplished. Note that this just shows how to fetch all revisions in the collection on a User, you'd need to iterate through them and match the Description field on 'Disabled':
var rally = require('rally'),
queryUtils = rally.util.query,
rallyApi = rally({
// Example key, not valid
apiKey: '_UkMasZfjPZfquDIMExfEKnAboQUlyT2SP4UppMHir',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'Query User Revisions',
'X-RallyIntegrationVendor': 'Stackoverflow user4211235',
'X-RallyIntegrationVersion': '1.0'
}
}
});
function onError(error) {
console.log('Failure!', error);
}
function queryUserRevisions(result) {
var revisions = result.Revisions;
rallyApi.query({
ref: revisions,
start: 1,
limit: Infinity,
order: 'RevisionNumber',
fetch: ['RevisionNumber','Description','CreationDate']
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User Revisions...');
console.log('Summary of revisions on User:')
console.log(result);
}
});
}
function queryUserRevisionHistory(result) {
rallyApi.query({
ref: result.Results[0].RevisionHistory,
start: 1,
limit: Infinity,
fetch: ['Revisions','RevisionNumber','Description','CreationDate']
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User Revision History. Querying Revisions...');
queryUserRevisions(result);
}
});
}
function queryUser(callback) {
rallyApi.query({
type: 'user',
start: 1,
pageSize: 2,
limit: 10,
order: 'CreationDate',
fetch: ['UserName', 'EmailAddress', 'RevisionHistory'],
query: queryUtils.where('UserName', '=', "user#company.com")
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User. Querying Revision History...');
callback(result);
}
});
}
queryUser(queryUserRevisionHistory);

CloudSearch javaScript API help to configure fq and query

I know I am doing wrong somewhere in setting parameters. Basically, I want to convert the below link to script.
Click here to check the query
aws.config.update({
region: 'us-east-1'
});
AWS.config.apiVersions = {
cloudsearchdomain: '2013-01-01',
// other service API versions
};
var csd = new AWS.CloudSearchDomain({
endpoint: 'search-vegme-user-7l3rylms73566frh4hwxblekn4.us-east-1.cloudsearch.amazonaws.com'
});
var params = {
query: 'nikhil',
/* required */
expr: 'distance=haversin(35.621966,-120.686706,latlong.latitude,latlong.longitude)&sort=distance%20asc&return=distance,displayname,profileimageurl',
filterQuery: 'latlong:['
44.37094377949903,
-78.40296337445523 ','
42.92362822050097,
-80.40316462554478 ']',
partial: true,
queryOptions: 'STRING_VALUE',
queryParser: 'simple,
return :'distance,id,fname',
sort: 'asc',
};
csd.search(params, function(err, data) {
if (err) {
console.log(err, err.stack); // an error occurred
} else {
console.log(data); // successful response
}
});
Instead of using the above method to get the nearby locations
I am using
the below link with HTTP module in my nodeJS
http://search-vegme-user-7l3rylms73566frh4hwxblekn4.us-east-1.cloudsearch.amazonaws.com/2013-01-01/search?q=nikhil&expr.distance=haversin(35.621966,-120.686706,latlong.latitude,latlong.longitude)&sort=distance%20asc&return=distance,displayname,profileimageurl
It will return all the top near locations for a given point
latlong is the valiable of type latlon
You need to add params something like this
var params = {
'q': queryString,
'cursor': "initial",
'size': 5,
'expr.distance': "(haversin(35.621966,-120.686706,latlong.latitude,latlong.longitude))",
'sort': "distance asc",
'q.parser': "structured",
'return': "dietsinceyear,fbprofileid,reasonforveg,verified,since,displayname,locale,link,tagline,email,followingcount,agerangemin,shortdescription,vegstory,lastupdated,timezone,diet,followercount,fbupdated_time,coverimageurl,lname,id,gender,profileimageurl,categoryids,fname,distance"
}

Sails.js handling attribute validation errors

In Sails.js it is possible to use different database connections for models and it is easy to change database (MySQL or MongoDB). The problem arises when I want to display validation errors. These are my codes:
Groups.js model
...
connection: 'MysqlConnection', //or connection: 'MongodbConnection'
attributes: {
id: {
type: 'string',
unique: true
},
name: {
type: 'string',
required: true
},
...
GroupsController.js controller:
...
//add group to database
Groups.create(group, function (err, data) {
if (err) {
console.log(err);
res.send('Error'); // is it possible to send only validation error
return;
} else {
res.send(data);
}
});
...
Should I handle each attribute validation error separately, is it possible to send only validation error?
MySQL returns:
Error (E_VALIDATION) :: 1 attribute is invalid ...
MongoDB returns:
Error (E_UNKNOWN) :: Encountered an unexpected error ...
you can try:
Model.catch(function(err) {
var inspect = Object.keys(err)// [ "reason","invalidAttributes", ".." ]
console.log( Object.keys(err.invalidAttributes) ) // ["name","etc.."]
})
to catch the error

Inserting an event with the nodejs google calendar API returns 400: "Missing end time"

I am trying to insert events via the Google Calendar API with a service account. The goal is to have one calendar that all users view: a server-to-server setup.
As of now, I can properly call the calendar API and list the events on said calendar:
var moment = require("moment"),
googleapis = require("googleapis"),
googleCal = googleapis.calendar("v3");
serviceEmail = "********#developer.gserviceaccount.com",
serviceKeyFile = "./key.pem";
var authClient = new googleapis.auth.JWT(
serviceEmail,
serviceKeyFile,
null,
["https://www.googleapis.com/auth/calendar"]
);
authClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
} else {
googleCal.events.list({
auth: authClient,
calendarId: "********#gmail.com",
fields: {
items: ["end","start","summary"]
}
}, function (err, CL) {
if (err) {
console.log(err);
} else {
console.log(CL);
}
});
}
})
This properly returns a JSON object that lists all the different objects on the calendar. However, when I try to insert an event directly below the googleCal.events.list call:
googleCal.events.insert({
auth: authClient,
calendarId: "primary",
resources: {
start: {
dateTime: "2014-07-23T18:25:00.000-07:00",
timeZone: "America/New_York"
},
end: {
dateTime: "2014-07-23T19:25:00.000-07:00",
timeZone: "America/New_York"
},
summary: "winning # life",
description: "winning # life description"
}
}, function (err, something) {
if (err) {
console.log(err);
} else {
console.log(something);
// do something else
}
})
The following 400 is returned:
{ errors:
[ { domain: 'global',
reason: 'required',
message: 'Missing end time.' } ],
code: 400,
message: 'Missing end time.'}
How do I go about fixing this? The authorization is clearly working—I know because I've used up my unauthorized requests for the day and because I can list all the events. I have also specified an endTime. Why is the google calendar API telling me that I haven't?
I think the problem is in the keyword "resources" on line 4 of your second snippet. Based on the documentation, it should be a "resource":
* #param {object} params.resource - Request body data

Categories

Resources