Tuesday, June 26, 2018

Call an AWS Lambda Function from another Lambda Function

AWS Lambda is I think one of the best additions to AWS, however it does have some issues becuase the architecture has changed over the years and one such problem the default VPC that it runs in. Default configuration runs great, but if you want better security, then not so much. But I digress. One of the most compelling features of Lambda is that you don't have to manager the VM or Docker Container. However because of that you might want to break up the responsibility between multiple Lambda functions, and in this case one Lambda will most certainly want to call another Lambda. So here's how you do that:

const aws = require('aws-sdk');
const lambda = new aws.Lambda({region: 'us-west-1'});

      FunctionName: 'LambdaFunctionName',
      Payload: JSON.stringify(event, null, 2)
   function(error, data) {
     if (error) {
        context.done('error', error);
     if (data.Payload){

Note: I really appreciate Lambda. But to be honest they are difficult to use. There is a time and a place to use them and it should be in every AWS developer's bag of tricks. The real trick I alluded to above is the VPC, but that's for a proper DevOps person to discuss the nuances of that. Also know that while in small uses Lambda is cost effective there is a cross over point where Lambda becomes more expensive than EC2 or Elastic Container Services (Docker).

Thursday, June 14, 2018

Docker ENV vs ARG

There are two types of variables in a Dockerfile, ENVs and ARGs. YOu define them in the Dockerfile like this:

ARG some_argument

This requires that you run:

$docker build --build-arg some_argument=something

Then there's ones with a default value.

ARG some_argument="default value"

You don't have to specify it during the docker build, but you can if you want.

ENV some_value=something
ENV some_other_value=${some_argument}

You can override these when you do docker run:

$docker run -e "some_value=others_stuff" ...