Clever/unique-port

Name: unique-port

Owner: Clever

Description: Lambda function for allocating unique ports via cloudformation

Created: 2017-01-11 20:25:38.0

Updated: 2017-01-11 20:54:26.0

Pushed: 2018-02-20 21:26:29.0

Homepage: null

Size: 15

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ECS Unique Port

Lambda-backed custom CloudFormation resource that produces a unique port.

How it works

This repo contains:

The port free list is managed with two DynamoDB tables:

Building and updating

You can build the code with

ke install_deps
ke

This will create the zip file (uniqueport.zip) ready to be uploaded to lambda. Navigate to your existing lambda function in the aws console and use the upload zip function to upload the newly built zip file.

Launching from scratch

If you don't already have this lambda function setup, the instructions below will set up the lambda function and all the necessary dynamodb tables.

  1. Build the code for the lambda function and upload it to S3:

    rt PUBLIC_AWS_BUCKET=clever-public-us-west-2
     release
    

    This will upload a file called uniqueport.zip into the bucket you specify.

  2. Launch the lambda function into a region that has lambda support, e.g. us-west-2:

    --region us-west-2 cloudformation create-stack \
    ack-name custom-cf-resource-uniqueport \
    mplate-body file://`pwd`/custom-cf-resource-uniqueport.json \
    pabilities CAPABILITY_IAM \
    rameters \
    meterKey=S3Bucket,ParameterValue=$PUBLIC_AWS_BUCKET \
    meterKey=S3Key,ParameterValue=uniqueport.zip
    
  3. Now you can use the resource in cloudformation configs. The following example just asks for a few ports (and does it in a different region than the lamda fn):

    l of the following are outputs of step 2
    rt LAMBDA_ARN=x
    rt DYNAMO_REGION=x
    rt DYNAMO_LOCK_TABLE=x
    rt DYNAMO_PORTS_TABLE=x
    

aws –region us-west-1 cloudformation create-stack \ –stack-name uniqueport-example \ –template-body file://pwd/example.json \ –capabilities CAPABILITY_IAM \ –parameters \ ParameterKey=Key,ParameterValue=example-key \ ParameterKey=LambdaArn,ParameterValue=$LAMBDA_ARN \ ParameterKey=DynamoRegion,ParameterValue=$DYNAMO_REGION \ ParameterKey=LockTable,ParameterValue=$DYNAMO_LOCK_TABLE \ ParameterKey=PortsTable,ParameterValue=$DYNAMO_PORTS_TABLE

```

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.