Manage environment to functions
Manage rolesServerless and customization environments in cloud providers. Through this management, arule customization business on the senior X Platform through the Cloud9 IDE, which allows those responsible for customization to have control over functionsServerless created at the cloud provider from the platform.
For complete technical documentation, accessComplete documentation available on the Dev.senior portal.
To learn more about how to debug a custom rule on the senior X Platform, watch our YouTube video below:
What can you do:

To be able to configure the environment, it is necessary to ensure that the access keys to the cloud provider are already properly configured. By default, the service uses the keys already entered in the global settings, however, there is the possibility of overwriting the access keys through the tenant settings:
- go to Technology > Configuration > By tenant and search for the fields intended for the cloud provider's configuration keys;
- fill in the information, clickTo save and wait for the success notification.

- Access Technology > Customization > Configure Environment > Manage Environment;
- With the cloud provider access keys properly configured, clickCreate Environment;
- If any of the steps fail, the try again button will be enabled. Click on it for the service to try to configure the environment again;
- Check the instructions received by email to access the environment;
- When the environment is completely configured, clickOpen environment to access the environment created in Cloud9.
Optionally, use the buttonUpdate status to update the information if there is a delay after configuring the passkey and before configuring the environment. If you choose this option, the information will be updated automatically every ten seconds, as there are cases where the environment configuration steps can take up to 40 seconds to complete.
Important
The person responsible for creating the environment needs to access it immediately after the creation has been completed, the environment will only be available to others after this step.
Senior provides an account for creating the environment, however, depending on its use, there may be extra costs. Contact the salesperson for more information.

Select the primitive to be customized through customizationrules, and click the buttonGenerate URL and fill in the name of the desired function. This screen allows the creation of rule points, which do not depend on the use of the SDK, that is, without the need to generate a URL, and just informing the desired URL.

The standard AWS Lambda created through the SDK has some information in the comments such as primitive name, domain, service and tenant. And your default code automatically responds with the message "Hello world". The environment is configured with theNodeJS in version 12 and allows the use of the JavaScript language.
After making changes to the function code:
- Open the AWS resources tab and select the function to which you want to upload changes;
- click inUpload so that your changes are automatically applied to the function code and are ready to be used.

Simple Lambda code using Node.js as a programming language:
'use strict';
/**
* Primitive name: getStages
* Nameof domain: platform
* Nameof service: functions
* Nameof tenant: brenon
**/
exports.handler = async (event) => {
return sendRes(200, JSON.parse(event.body));
};
const sendRes = (status, body) => {
body.helloWorld ="Hello World";
var response = {
statusCode: status,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
};
console.log(body);
return response;
};
For Bridge to correctly interpret the response, it is necessary to follow appropriate formatting.payload, informing some basic items such as headers, body and response code.
Lambda function using Node.js 6.10 as programming language, accessing the AWS S3 service:
var AWS = require('aws-sdk');
const BUCKET = process.env.BUCKET_NAME;
const REGION = process.env.REGION ||'sa-east-1';
constPREFIX ='events/';
var s3 =new AWS.S3( { region: REGION });
exports.handler = (event, context, callback) => {
var params = {
Bucket: BUCKET,
Prefix: PREFIX
};
s3.listObjectsV2(params,function(err, date) {
if (err) {
console.log(err, err.errStack);
var response = {
statusCode: 500,
body : JSON.stringify({ message:"Error retrieving calendar" }),
headers: {
"Access-Control-Allow-Origin":"*"
},
isBase64Encoded: false
}
callback(null, response);
} else {
collectEvents(data, callback);
}
});
};
function collectEvents(items, callback) {
let totalObjects = items.KeyCount;
let events = [];
items.Contents.forEach(obj => {
s3.getObject({ Bucket: BUCKET, Key: obj.Key },function(err, object) {
if (err) {
console.log(err, err.st);
}else {
let content = object.Body.toString("utf-8");
let date = extractDate(obj.Key);
if (date && content.length > 0 && date < new Date()) {
events.push({ date: date, content: content});
}
}
if (--totalObjects == 0) {
events.sort((e1, e2) => e2.date - e1.date);
let result = { events : events };
let response = {
statusCode: 200,
body: JSON.stringify(result),
headers: {
"Access-Control-Allow-Origin":"*"
},
isBase64Encoded: false
};
callback(null, response);
}
})
})
}
function extractDate(objectKey) {
let regex = new RegExp("^" + PREFIX);
let dateStr = objectKey.substr(0, objectKey.length - 3).replace(regex, '');
let dateRegex = new RegExp("([0-9]{4}\-[0-9]{2}\-[0-9]{2})\-([0-9]{2}\- [0-9]{2})", "g");
let matches = dateRegex.exec(dateStr);
if(matches) {
return new Date(matches[1] + "T" + matches[2].replace('-', ':'));
}else {
return null;
}
}
For Bridge to correctly interpret the response, it is necessary to follow appropriate formatting.payload, informing some basic items such as headers, body and response code.

Go to Technology > Customization > Rules > Features (API) and activate the custom function.
The SDK aims to help the user configure an environment for executing customized rules. Even with the focus on using the customization service, it was decoupled from other services. With this, the functions sent to the cloud server can be consumed by any service.
Requests for a role must have the following headers: seniorx-tenant-api-key and seniorx-tenant-domain.
The access URL and API KEY can be obtained by the SDK primitives.