• Configuring the VPC so we can call the database posted on 10 May 2017

    Ahh the final part.

    So if you're using AWS you're most likely using RDS. If you're using RDS then you've got a database, and if it's in production then hopefully you've disabled public access and haven't configured it to allow a connection from any IP address.

    If this is the case then the moment we test our Lambda, it's going to fail with a timeout.

    {
      "errorMessage": "2017-03-23T17:12:36.269Z e0474e8b-0feb-11e7-a0fe-276de97e95bf Task timed out after 15.00 seconds"
    }
    

    This happens because it cannot connect to the database, if the lambda execution time is less than your database timeout then this happens. Otherwise if the inverse is true you would get the database timeout exception rather than the lambda timeout exception.

    Read more...

  • Building / Publishing a .NET Core app using AWS Tools posted on 21 Mar 2017

    Now that we've got everything, we need to deploy it, however if we build it using dotnet clr it will fail.

    "cause": {
      "errorType": "TypeInitializationException",
      "errorMessage": "The type initializer for 'Npgsql.TypeHandlerRegistry' threw an exception.",
      "stackTrace": [
        "at Npgsql.TypeHandlerRegistry.Setup(NpgsqlConnector connector, NpgsqlTimeout timeout, Boolean async)",
        "at Npgsql.NpgsqlConnector.<Open>d__137.MoveNext()",
    

    That's because Npgsql need's to load some dependencies but the Lambda's don't understand that. No matter how I publish, restore for a target runtime and publish agains that, it doesn't seem to work. However, AWS have their own toolkit for publishing lambda's.

    Read more...

  • Saving / Retrieving data using Marten posted on 18 Mar 2017

    So far we have created a basic lambda, deployed it into AWS, and executed it. However, it doesn't do anything useful. While there are many things you can do, one of the things you're most likely going to want to do is touch a database. But let's get a little bit fancy and do it with Marten.

    If you don't know Marten, you're missing out. It's a LOT of fun. There's two parts to Marten, an event store, and the super awesome fun bit that I love. The Document Database.

    Marten uses PostgreSQL's fancy JSONB data type to store documents in the database, with an API built on top to make working with your domain easier without having to worry about your schema. Check it out.

    http://jasperfx.github.io/marten/

    Let's get started.

    Read more...

  • Building / Configuring the Lambda into AWS posted on 16 Mar 2017

    Now after part 1, we should have a basic lambda ready to build and deploy. Because this is such a basic handler, this will be published using the dotnet sdk, but if you have dependencies it's best to use the AWS Tools which I will show in part 4.

    Publishing the project

    Publishing is easy! All we need to do is run publish

    phill@DESKTOP-599M841 D:\CSharpLambdaSample\HelloWorldLambda
    $ dotnet publish
    Microsoft (R) Build Engine version 15.1.548.43366
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      HelloWorldLambda -> D:\CSharpLambdaSample\HelloWorldLambda\bin\Debug\netcoreapp1.0\HelloWorldLambda.dll
    

    We can change the output directory by an -o argument, and change from debug to release passing in a -c argument.

    Read more...

  • Creating a good old Hello World AWS C# Lambda posted on 15 Mar 2017

    So finally .NET Core Tools has reached 1.0 and after playing around... it's actually usable now. I can do all the things easily, that I once found difficult.

    This blog series is about creating a basic sample handler for an AWS C# Lambda, and extending it to configure a VPC, and query PostgreSQL using Marten, all using VSCode.

    To follow this series you need to install:

    Creating the class library

    Let's start by creating a class library, create a folder some where, and navigate to it in terminal or command line. Then run the command:

    dotnet new classlib -n HelloWorldLambda -f netcoreapp1.0

    It's important you target netcoreapp1.0 as this is what's supported on AWS C# Lambda's right now.

    phill@DESKTOP-599M841 D:\CSharpLambdaSample
    $ dotnet new classlib -n HelloWorldLambda -f netcoreapp1.0
    Content generation time: 22.1887 ms
    The template "Class library" created successfully.
    

    Now you can open up the folder in VSCode.

    Read more...

  • PostgreSQL and it's Array data type posted on 07 May 2016

    Switching between PostgreSQL and SQL Server, I've only ever really used the features of SQL Server in PostgreSQL.

    Lately after discovering Marten, I've been exploring features of PostgreSQL.

    Array data types, are the new awesome (today as of writing this, for me)

    Defining the table

    Using a really boring example, of a table, with an id, and an array of values.

    drop table if exists test_arrays;
    
    create table test_arrays (
        id int,
        values int[]
    );
    

    Above you can see the values is declared as an array type by adding [] to the end of int, this declares it as an int array.

    Read more...

  • Using AWS's API Gateway to recieve Sendgrid event hooks and shove them in SQS posted on 03 Jan 2016

    Sendgrid hooks allow you to recieve notifications of events that occur to the emails that you send, such as, was the email clicked, was it bounced, was it unsubscribed, etc.

    A list of events can be found here

    When sendgrid send the events, they send an array of events, so it may not be ideal to process those as they come in, and rather just accept them and process them when you can. To do that you can use AWS's API Gateway to accept the request and push the JSON body to SQS.

    Steps:

    1. Setting up the Queue
    2. Setting up the Policy
    3. Setting up the Role
    4. Creating the API Gateway
    5. Test with Console
    6. Test with Postman

    Read more...

  • GZip with scriptcs in Octopus Deploy posted on 21 Oct 2015

    I had this crazy problem tonight. I wanted to upload all my assets for my website into AWS S3, but I needed to gzip them first before sending them.

    Usually I do this in Team City with Grunt, but all my variable replacement is done in Octopus Deploy depending on the environment.

    • Staging = S3 URLs
    • Production = CloudFront URLs

    If the compression is done in Team City, variable replacement cannot happen on the GZipped file.

    I decided to move it to Octopus Deploy, my first thought was, could I run a node.js task in Octopus Deploy, the more I thought about it tho, I realised I don't want to install a dependency on node.js on the server.

    Second thought was to use Powershell... but I'm a real powershell no0b.

    Read more...

  • Permament redirect to HTTPS with IIS posted on 16 Aug 2014

    Google has just recently updated their search results to give higher ranking to sites with an SSL Certificate, than to sites without, which is one of the best changes Google has made in recent years. There really is no excuse for not having a cert now. (note, this is limited to small portion of sites but lets assume that this will be rolled out if Google proves it to be worth while)

    googleonlinesecurity - https-as-ranking-signal_6.html

    Unfortuntely for me it seems Github Pages does not support Certificates on custom domain names, yet... :( hopefully they will support this eventually so that I can avoid moving my blog.

    So one thing that pops up in the Nancy channel on JabbR every-now-n-then, is how to make all modules require SSL.

    From within a module you can call:

    this.RequiresHttps()
    

    And this will push the site into https, but having to write this everywhere is rather annoying, and during development on your local machine this is a bit of a hassle. Despite Visual Studio supporting an HTTPS url...

    Read more...

  • Taking snap shots of a Video & displaying it posted on 09 Jun 2014

    Now we've loaded an image/video, we've captured the drop event, we've displayed it...

    But what about taking screen grabs of a video?

    To start with I'll go back to the code we used in Part 1, so we have an input, a load button, and a video control:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>      
        <div>
            <input type="file" id="video-input">
            <input type="button" value="Load Selected Video" id="load-video" />
        </div>
    
        <div>
            <video id="video-container" controls></video>
        </div>
    </body>
    </html>
    

    Racing ahead we load that up:

    Read more...