loading...

Use technology to strengthen your relationship

gyandeeps profile image Gyandeep Singh Originally published at gyandeeps.com ・3 min read

This was originally posted here

I got married in December 2014 and after getting married within a month my wife had to move to Omaha, Nebraska to work towards her MIS degree (2 year course). I was left alone in Kansas City (bachelor again :) ). Since I work during the week and on weekends I do some open source work my life was very busy. Only at night I used to talk to my wife for few minutes and then go off to bed. My wife was never happy with how much time I gave her from the day and I didn't even text her. So her biggest complain was that I don't talk to her enough during the day, even don't send text messages. I know every man alive on the planet has heard the same words from the other half.

After all this, one day I decided to do something about this and being a software engineer my first thought was why not use technology and automate this type of human interaction. And that is when I decided to spend few hours on this project.
Now I am going to switch gear and convert the above situation into technical user story and solve the problem in hand.

User Story

  • Send text messages to wife everyday (I chose to send only 1 message).
  • Make sure the message are appropriately worded with words like "love", "miss you", etc.

Design

I wanted to automate this process so that I can keep doing what I do and my wife still receives messages. This way I will also learn about AWS since everyone is talking about it.

  • Use Amazon web services
  • Build a script which picks a nice message and sends the message everyday.
    • I chose to send it at 4PM CDT (random time)

Technical work

Use these Amazon web services:

  1. CloudWatch1
  2. Lambda2
  3. SNS3

CloudWatch

Setup cloud watch to run my lambda function at a particular time of the day. Its like a cron job.

  • Create a rule with a name of your choice.
  • Specify the time interval to run.
    • used Cron expression 0 21 * * ? * (4PM CDT)
  • Select your lambda function inside the target.

Lambda

This is the brain of this whole project. When this function is triggered by the CloudWatch, it basically picks up a random message from the array of messages and then posts the message to SNS topic (explained later).

  • Create a Lambda function with hello world template
  • Give it some name, description and use NodeJS as the environment.
  • Use the below code and fill in the required information as mentioned inside the comments
var AWS = require("aws-sdk");
var messages = [ // this where you want to put all the messages, I have like 100 messages here
    "hi",
    "bye"    
];

function getRandomMessage(){
    return messages[ Math.floor(Math.random() * messages.length ];
}

exports.handler = (event, context, callback) => {
    var sns = new AWS.SNS();
    var params = {
        Message: getRandomMessage(),
        Subject: "<Give a subject name (I just used my wife's name)>",
        TopicArn: "<use the topic arn number from SNS>"
    };
    sns.publish(params, context.done);
};
  • Create a role which gives permission to your lambda function to post on SNS topic4.

SNS

We will use SNS to setup a topic and when ever you post on the topic it sends a SMS to all the subscribers.

  • Create a topic with any name of your choice
    • You will get the topic arn which you want to use inside your lambda function code
  • Inside the topic create subscriptions (You want to do it one here unless you plan to send to to many people :p )
    • Set protocol to SMS
    • Set the cell number

Conclusion

This helped a lot since my wife gets so excited when she gets these messages everyday. She knows its me who is sending these messages but I always deny it. Now she will find out after reading this post.

References

  1. CloudWatch 

  2. Lambda 

  3. SNS 

  4. AWS Permission model 

Posted on by:

gyandeeps profile

Gyandeep Singh

@gyandeeps

Associate lead Software Engineer (@cerner) Web, JavaScript, NodeJs, automation, being human, Dad, communication s key 😎 #StriveForGreatness

Discussion

markdown guide
 

You wrote all this because you didn't want / couldn't be bothered to pick up your phone and text your wife? This just seems wrong...or strange but definitely not a good thing.

Or were you just taking the hand out of all of us with this post?

 

plot twist: his bots revealed at him and started to share the shady strats of a half-human half-machine who didn't want to live the social parts of his life. Hahaha, ok just kidding. :)

 

This was fun and my wife liked it ... fun experiment nothing more...

 

Did this really strengthen your relationship? 🙈

 

I mean it was fun... after few days when my wife found out, she was impressed n she liked the gesture.. 😊