AWS CloudFormation example for S3 bucket

Typical Cloudformation for an S3 bucket with block all public access enabled:

Resources:
  S3BucketExample:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: s3-bucket-name
      PublicAccessBlockConfiguration:
        BlockPublicAcls: true
        BlockPublicPolicy: true
        IgnorePublicAcls: true
        RestrictPublicBuckets: true

‘serverless invoke local’ with Java Lambdas

If you create a Java Lambda with the provided template, you’re probably returning a response using the provided ApiGatewayResponseClass. If you run your Lambda locally with ‘serverless invoke local –function functioname’, you’ll see a response like this:

Serverless: Invoke invoke:local
Serverless: In order to get human-readable output, please implement "toString()" method of your "ApiGatewayResponse" object.

com.serverless.ApiGatewayResponse@3bd3d05e

Any other logger output will appear in your console, but in order to see the actual content of your ApiGatewayResponse, add a toString() method as the message suggests.

You include any of the properties in ApiGatewayResponse, but if you’re just interested in the JSON payload in the body of the response, then just adding this will return the body:

public String toString(){
    return this.body;
}

Learning Java 8 Streams

I’ve never had a good opportunity to use Java 8 Streams since traditional iteration approaches always seemed to be appropriate for what I needed. Working on my Sudoku related projects (in particular an implementation of a Human Solver) I needed an approach to count occurrences of numbers in Lists and also find where pairs existed in Lists.

To get started, I started with a number of simpler examples to gradually work up to what I was looking for. I’ve collected a number of my examples in this project here.

Creating a new AWS Lambda project with Serverless

Assuming the Serverless cli is already installed (here), init a new project with ‘serverless’ and answer the following questions:

% serverless       
 Serverless: No project detected. Do you want to create a new one? Yes
 Serverless: What do you want to make? AWS Node.js
 Serverless: What do you want to call this project? lambda-example
 Project successfully created in 'lambda-example' folder.

To deploy, run ‘serverless deploy’