I want to send AWS CodeCommit commit message to a HipChat room. I already have a lambda function which gets triggered for a particular commit. What I need is to get commit detail messages from CodeCommit. Commit ID, commit message, branch name etc.
Inside lambda you can require sdk then get parameters from lambda event.
const AWS = require('aws-sdk')
let codecommit = new AWS.CodeCommit();
var params = {
commitId: 'STRING_VALUE', /* required */
repositoryName: 'STRING_VALUE' /* required */
};
codecommit.getCommit(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Depending on the info you get in lambda event parameters you can call one of those methods from sdk.
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CodeCommit.html
Related
I have been working with AWS for the last month and I need to know how can we update the step function without changing the name of the file.
The way that the documentation provided to make the changes in the step function is to change the name of the existing one and add the changes in the file. But that will eliminate the logs that have been created in the AWS CLI.
For Example, if I replace the following code with something else I have to change the whole dynamic of the project in order to make them appear in the AWS CLI
Can somebody please provide a solution for this??
The update part can be done through an AWS configuration command. Follow the commands below, it will keep all the changes in the execution logs as wells.
let aws = require('aws-sdk');
let roleArn = `roleARN goes here`;
let params = {
name: stepFunctionName,
roleArn: roleArn,
definition: JSON.stringify(definitionGoesHere),
};
let stepFunctions = new aws.StepFunctions();
stepfunctions.createStateMachine(params, function (err, data) {
if (err) {
console.log("error occured while creating the step function");
console.log(err, err.stack);
if (err.code === "StateMachineAlreadyExists" && err.statusCode === 400) {
let paramsUpdate = {
stateMachineArn: "stateMachine ARN for the existing stateMachine",
definition: JSON.stringify(definition),
loggingConfiguration: {
includeExecutionData: true,
},
roleArn: roleArn,
};
stepfunctions.updateStateMachine(
paramsUpdate,
function (error, updateData) {
if (error) {
console.log("error occured while updating the step function.");
console.log("Error", error.stack);
}
console.log("step function updated successfully");
console.log("response", updateData);
}
);
}
console.log(
"step function does not exist and the function creation and update faild in the process."
);
console.log("definition", definition for the stateMachine);
} // an error occurred
else console.log(data); // successful response
});
I am working on Amazon Connect application. I am using lambda for handling backend data. My requirement is to change agent status from lambda call using AWS SDK/Stream API. I know we can do this from Amazon Connect stream api via CCP. But in my case, it needs to be done from lambda call. I checked documentation of AWS Connect SDK but there is not direct method available for changing Agent state.
Kindly suggest.
Thanks,
gans
You can directly set the agent state using the Amazon Connect Streams API:
var state = agent.getAgentStates()[0];
agent.setState(state, {
success: function() { /* ... */ },
failure: function(err) { /* ... */ }
});
Reference: https://github.com/amazon-connect/amazon-connect-streams/blob/master/Documentation.md#agent-api
The April 2022 Connect release has added an API call to do this finally!
There is now a PutUserStatus operation that will update a given agents status.
The call to the operation in javascript is:
const AWS = require('aws-sdk');
const connect = new AWS.Connect();
let params = {
AgentStatusId: 'STRING_VALUE', /* required */
InstanceId: 'STRING_VALUE', /* required */
UserId: 'STRING_VALUE' /* required */
};
connect.putUserStatus(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
where:
UserId is the guid identifier of the user.
InstanceId is the guid identifier of the Amazon Connect instance.
AgentStatusId — the guid identifier of the agent status. This can be retrieved via the listAgentStatuses operation.
More info here:
https://docs.aws.amazon.com/connect/latest/APIReference/API_PutUserStatus.html
I have created a FIFO SQS queue.
When sending a message to the queue using the below params,
var params= {
MessageBody: payload,
QueueUrl: sqsURL + body.device + ".fifo"
}
sqs.sendMessage(params, function(err, res) {
err ? callback(err) : callback(null, res);
});
I get a warning that says "missing parameter messagegroupid"
I then proceed to add in MessageGroupId into my params.
var params= {
MessageBody: payload,
MessageGroupId: "posts",
QueueUrl: sqsURL + body.device + ".fifo"
}
sqs.sendMessage(params, function(err, res) {
err ? callback(err) : callback(null, res);
});
SQS then throws me "UnexpectedParameter: Unexpected key 'MessageGroupId' found in params".
Am confused by this set of conflicting instructions.
I'm using the same SDK region in both my createQueue and sendMessage command.
var sqs= new aws.SQS({ region: "us-east-2" });
I ran into this same error using Lambda (hence finding your post). Wondering if they forgot to refresh the native SDK, I uploaded the latest version of the SDK(2.7.7) with my function and the error went away.
Since uploading the SDK removes the ability to edit in Lambda, I then deleted it and re-uploaded the function the error came back :(.
So for now, if you want to use it with Lambda, you have to include the SDK with your deployment package.
You've missed passing "MessageGroupId" parameter. You should pass Message group id as a parameter. It is mandatory for FIFO.
Please refer the below-mentioned link,
https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sqs-2012-11-05.html#sendmessage
I just created this function in AWS Lambda to start multiple instances. However when i run the test, it only starts one of the instances instead all the instances in the array. Is this a problem with how i have my array defined in the function? Lambda did not throw a json error so i assumed all was well. I am using the Node.js 4.3 runtime format.
var AWS = require('aws-sdk');
exports.handler = function(event, context) {
var ec2 = new AWS.EC2({region: 'us-west-1'});
ec2.startInstances({InstanceIds : (['i-a11111'],['i-a22222'],['i-a33333'],['i-a44444']) },function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
context.done(err,data);
});
};
From the AWS JavaScript SDK documentation, the InstanceIds parameter is supposed to be an array of strings:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#startInstances-property
This should be the correct format:
{ InstanceIds : ['i-a11111','i-a22222','i-a33333','i-a44444'] }
I have an AWS Lambda function, that need's ~ 30 seconds.
When I connect it to the API Gateway, it's sending a 504 because of the 5 second timeout. So my easyCron Job is failing and will not try it again (I only have a free plan)
So I need an API, that sends a correct 200 status.
My Idea:
Invoke the long term lambda via a short term lambda.
The policy is allowing the invocation.
Here is the code
var AWS = require('aws-sdk'),
params = {
FunctionName: 'cctv',
InvocationType: 'RequestResponse',
LogType: 'Tail'
},
lambda;
AWS.config.update({region: 'us-east-1'});
lambda = new AWS.Lambda();
exports.handler = function (event, context) {
'use strict';
lambda.invoke(params, function (err, data) {
if (err) {
console.log(err, err.stack);
}
else {
console.log(data);
}
});
context.succeed('hey cron job, I think my lambda function is not called');
};
But I think, context.succeed() aborts the execution of lambda.invoke()
Do you have any idea how to solve this?
This is incorrect
InvocationType: 'RequestResponse'
You should use
InvocationType: 'Event'
From http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax
By default, the Invoke API assumes "RequestResponse" invocation type. You can optionally request asynchronous execution by specifying "Event" as the InvocationType.
Rather than directly calling your 30+ second Lambda function, you could trigger it from an SNS or S3 PutObject event. This would be asynchronous to your API Gateway route, so it can return very quickly. Of course, you would not have the outcome of the Lamdba job at that time.