I'm deeply confused trying to integrate AWS API Gateway with AWS Lambda, because i'm trying to execute a lambda function through the GET method and always my function is returning invalid parameter.
{"errorMessage":"Error - Invalid Group ID - undefined - alexa id:
undefined"}|
It happens because the parameters was not arriving to the function and idgrupo variable is <=0.
I'm trying to execute a lambda function with URL at this form:
domain.execute-api.us-east-1.amazonaws.com/prod/chkneopairtoken?idgrupo=3823&clientId={321356-6666-4745}&keypair=90809276
And in my Lambda function i'm doing it:
var idgrupo = event.idgrupo;
var alexaClientId = event.clientId;
var keypair = event.keypair;
if (idgrupo > 0){
} else{
console.log("Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId + " - ");
//callback(null, "Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId);
context.fail("Error - Invalid Group ID - " + idgrupo + " - alexa id: " + alexaClientId);
}
Are there the possibility to do what i'm trying to do?
I think it is not an integration error between API Gateway and AWS Lambda, because the function returns my custom error message, and I believe it is a transfer parameters error.
Go back to the "Integration Request" of your resource GET, under "Body Mapping Templates"
Select for the recommended option for "Request body passthrough"
Add a mapping template (clicking on the action "Add mapping template")
Write "application/json" for the content type
Add this template
{
"idgrupo" : "$input.params('idgrupo')",
"clientId" : "$input.params('clientId')",
"keypair" : "$input.params('keypair')"
}
In your API Gateway console, under "Integration Request", in the "Mapping Template" section, create a template for the content-type that you are submitting, and then just select "Method Request passthrough". This will pass everything through to the Lambda function.
Then in your Lambda function code you will need to reference those URL parameter values via event.params.idgrupo, event.params.clientId etc.
Related
I've set up Signalr on my MVC 5 website, and most of it is working fine. For example, if I try and send a test message using Javascript like so it works great:
$.connection.hub.start().done(function () {
chat.server.send("Username", "This is a test message");
});
And my C# send method in the Hub sends the message like so:
public void Send(string username, string message)
{
string name = Context.User.Identity.Name;
Clients.Group(username).getMessages("From: " + name + " - " + message);
}
The problem arises when i try to call the Send method via C#, like this:
ChatHub ch = new ChatHub();
ch.Send("Username", "This is a test message");
When it hits the method during debugging, the Context object is null and it fails.
Essentially, a user sends a message in the View, it hits a controller method, this method calls a notification method in a separate helper class, and this separate class calls the Send method of my Signalr Hub.
Would I need to get the context in the controller, and pass it to the helper class, and then to the Hub? Or is there a better, alternative approach?
Thanks.
UPDATE
I did manage to get the username using:
string name = System.Web.HttpContext.Current.User.Identity.Name;
However, even if I do this, it now throws an exception when it hits this line:
Clients.Group(username).getMessages("From: " + name + " - " + message);
So i think there's a context issue when calling Send from C# only (not from Javascript)
So it turns out from reading this: https://stackoverflow.com/a/36988086/4181058
"If you want to send messages to clients from your own code that runs outside the Hub class, you can't do it by instantiating a Hub class instance, but you can do it by getting a reference to the SignalR context object for your Hub class."
So my solution instead of this:
ChatHub ch = new ChatHub();
ch.Send("Username", "This is a test message");
Was this:
var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
context.Clients.Group(username).getMessages("From: " + name + " - " + message);
I have this var called turnosFinal2
{"title":"Mariel Guerrieri","start":"2020-03-18T09:30:00","end":"2020-03-18T10:30:00"}
,{"title":"Agustin Guerra","start":"2020-03-17T12:30:00","end":"2020-03-17T13:30:00"}
,{"title":"Maria Marco","start":"2020-03-21T13:00:00","end":"2020-03-21T14:00:00"}
And a fullCallendar with the events propierty:
events: [{
title: 'Agustin Guerra',
start: '2020-03-12T10:30:00',
end: '2020-03-12T11:30:00'
}]
In this case, the event is static and it successfully renderized when i load the webpage.. I wanna replace this static event for dinamic data
Then, i transform the var turnosFinal2 on this way:
var turnosFinal = "[" + (turnosFinal2.replace(/"title"/g, "title").replace(/"start"/g, "start").replace(/"end"/g, "end").replace(/"/g, "'")) + "]";
Getting now:
[{title:'Mariel Guerrieri',start:'2020-03-18T09:30:00',end:'2020-03-18T10:30:00'}
,{title:'Agustin Guerra',start:'2020-03-17T12:30:00',end:'2020-03-17T13:30:00'}
,{title:'Maria Marco',start:'2020-03-21T13:00:00',end:'2020-03-21T14:00:00'}
]
from my point of view this variable should now be able to go in the value of events, so i put it
events: turnoFinal,
But i get this console error:
main.js:4329 GET http://localhost/pos/[%7Btitle:'Mariel%20Guerrieri',start:'2020-03-18T09:30:00',end:'2020-03-18T10:30:00'%7D,%7Btitle:'Agustin%20Guerra',start:'2020-03-17T12:30:00',end:'2020-03-17T13:30:00'%7D,%7Btitle:'Maria%20Marco',start:'2020-03-21T13:00:00',end:'2020-03-21T14:00:00'%7D]?start=2020-03-16T00%3A00%3A00-03%3A00&end=2020-03-23T00%3A00%3A00-03%3A00 403 (Forbidden)
main.js:5273 Request failed {message: "Request failed", xhr: XMLHttpRequest}
If i click on first line (localhost/pos/[%7...) get this:
¡Forbidden Access!
You do not have permission to access the requested object.
The object is read protected or
the server cannot read it.
How to create consumergroups in eventhub using nodejs in Azure?
I tried to replicate what .net SDK offers, it did not work.
const { NamespaceManager } = require("#azure/service-bus");
let namespaceManager = NamespaceManager.CreateFromConnectionString(eventHubConnectionString);
let ehd = namespaceManager.GetEventHub(eventHubPath);
namespaceManager.CreateConsumerGroupIfNotExists(ehd.Path, consumerGroupName);
Here is the process that worked:
https://learn.microsoft.com/en-us/rest/api/eventhub/create-consumer-group
Steps:
Create SAS Token
Supply the right headers and make a https call to REST api
You can create it only once, if you call for the second time, it will throw an 409 error. If you want an update or insert call, you need to check for it.
SAS Token:
https://learn.microsoft.com/en-us/rest/api/eventhub/generate-sas-token
uri -- url of your eventhub
saName -- Name of your Managed Policy
saKey -- Primary / Secondary Key of your EventHub Manage Policy (Ensure it has the Manage)
function createSharedAccessToken(uri, saName, saKey) {
if (!uri || !saName || !saKey) {
throw "Missing required parameter";
}
var encoded = encodeURIComponent(uri);
var now = new Date();
var week = 60*60*24*7;
var ttl = Math.round(now.getTime() / 1000) + week;
var signature = encoded + '\n' + ttl;
var signatureUTF8 = utf8.encode(signature);
var hash = crypto.createHmac('sha256', saKey).update(signatureUTF8).digest('base64');
return 'SharedAccessSignature sr=' + encoded + '&sig=' +
encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + saName;
}
Request Parameters:
URL:
https://your-namespace.servicebus.windows.net/your-event-hub/consumergroups/testCG?timeout=60&api-version=2014-01
Headers:
Content-Type: application/atom+xml;type=entry;charset=utf-8
Host: your-namespace.servicebus.windows.net
Authorization: {replace with the content from your SAS Token}
Payload:
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<ConsumerGroupDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">Any name you want</ConsumerGroupDescription>
</content>
</entry>
Possible Return Statuses:
201 -- Successful Creation
404 -- Not found, you are using a name that does not exist
409 -- The messaging entity 'XXX' already exists.
If you notice any other issues, please leave a comment.
Event hubs Node.JS SDK doesn't support management operations.
Try a management client like https://www.nuget.org/packages/Microsoft.Azure.Management.EventHub/
I am getting this following error:
exception calling "UploadString" with "2" argument(s): "The remote server returned an error: (500)
Internal Server Error." At C:\Cinegy_Type\Helpers-Type.ps1:146 char:5 + $web.UploadString($url,
$xmlDoc.OuterXml) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [],
MethodInvocationException + FullyQualifiedErrorId : WebException
The method is this:
function Type-UpdateVariable([string]$name, [string]$value, [string]$type = "Text", [string]$server="localhost", [int]$instance=0)
{
#make a Type PostRequest XML document using .Net XML document object
$xmlDoc = New-Object System.Xml.XmlDocument;
#add root element for request - which is a 'PostRequest' element
$xmlRootElem = $xmlDoc.AppendChild($xmlDoc.CreateElement('PostRequest'));
#create SetValue element and define variable Name, Type and Value
$xmlSetValueElem = $xmlRootElem.AppendChild($xmlDoc.CreateElement('SetValue'));
$xmlSetValueElem.SetAttribute("Name", $name);
$xmlSetValueElem.SetAttribute("Type",$type);
$xmlSetValueElem.SetAttribute("Value", $value);
#create a .Net webclient which will be used to perform the HTTP POST
$web = new-object net.webclient
#Air requires that the data is in XML format and declared properly - so add the HTTP Header to state this
$web.Headers.add("Content-Type", "text/xml; charset=utf-8")
#perform the actual HTTP post to the IP and port (which is 5521 + instance number) of the XML data
$url = "http://" + $server + ":" + (5521 + $instance) + "/postbox"
$web.UploadString($url, $xmlDoc.OuterXml)
}
Line 146 is:
$web.UploadString($url, $xmlDoc.OuterXml)
what I do not understand is that this was working yesterday.
The full code can be found here: (Do not use line number here for reference, this has 3 scripts.)
https://pastebin.com/RtisgmiB
The web server you're posting to is having a problem; see meaning of a HTTP status code 500. Unless the data passed to your function are problematic, your code looks fine. There is nothing you're missing in that Powershell error message, which would give you a clue as to the issue.
Check the error log on the web server (best option)
Output the parameters to the console with the purpose of submitting the request manually through Postman, cURL, etc.
Good luck!
I followed this guide to integrate google sign in: https://developers.google.com/identity/sign-in/web/
But when I click the sign in button a pop up comes and goes but doesn't provide any information of the user.
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
In console I am not getting any information.
I fixed the problem by using right URL with the port number in Authorized JavaScript origins field in "Create a Project and Client ID" section.
And I also enabled Google+ Api for the project.