Skip to content

Instantly share code, notes, and snippets.

View SlootSantos's full-sized avatar
😎
Rollin'

Flosloot SlootSantos

😎
Rollin'
View GitHub Profile
const server = require('express')();
const axios = require('axios');
const createClient = require('../client');
// very same thing as in databaseService.js
const serviceDefinition = {
name: 'anyService',
ipv4: '127.0.0.1',
port: 3001
};
const server = require('express')();
const axios = require('axios');
const createClient = require('../client');
// very same thing as in databaseService.js
const serviceDefinition = {
name: 'anyService',
ipv4: '127.0.0.1',
port: 3001
};
const REGISTRY_PROTO_PATH = `${__dirname}/protos/registry.proto`;
// I personally prefer the promise syntax over
// the callback syntax
// nonetheless the functionality won't change at all if you go with callbacks
// but to actually turn the callback signature of those clients function into a promise based one
// we need a utility that is baked into node natively
// promisify
const { promisify } = require('util');
const grpc = require('grpc');
// we create an express instance
// and we pull in the the function to create an gRPC client we defined before
const server = require('express')();
const createClient = require('../client');
// well.. this is on our localmachine
// hence we know for sure where what location this process has.
// in production you'd want to come up w/ something more flexible
const serviceDefinition = {
name: 'databaseService',
// we need to tell the compiler which version we're using
syntax = "proto3";
package registry;
// here we define the service and methods we're going to use later on
// to do the registration process
service Registry {
rpc Register (Registration) returns (RegisterResponse);
rpc Unregister (Registration) returns (RegisterResponse);
// let's create a variable for the path of the .proto file
const REGISTRY_PROTO_PATH = `${__dirname}/protos/registry.proto`;
// import grpc and the loader
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
// here we actually load the proto content
const packageDefinition = protoLoader.loadSync(REGISTRY_PROTO_PATH);
// and then we create the definition of it
// so that we can go ahead and use it
const { registry: registryProto } = grpc.loadPackageDefinition(packageDefinition);
@SlootSantos
SlootSantos / Dockerrun.aws.json
Last active June 29, 2020 13:25
Code following the Medium article on how to stream logs from Beanstalk Multicontainer Platform to Cloudwatch
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "nginx",
"image": "nginx",
"essential": true,
"memory": 128,
"portMappings": [
{
# eb application #
resource "aws_elastic_beanstalk_application" "streaming_test" {
name = "streaming_test"
description = "This is the streaming test application"
}
# eb environment #
resource "aws_elastic_beanstalk_environment" "streaming_test_env" {
name = "streaming-test-env"
application = aws_elastic_beanstalk_application.streaming_test.name
### BEGIN .ebextensions/logs.config
files:
"/etc/awslogs/config/stdout.conf":
mode: "000755"
owner: root
group: root
content: |
[docker-stdout]
log_group_name=/aws/elasticbeanstalk/StreamingTest-env/docker-stdout
log_stream_name={instance_id}
#!/usr/bin/env bash
# This fetches the AWS CLI
# inflates it
# and sets location to the path
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# set the credentials to the default AWS CLI configuration file