citium

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2018 License: MIT Imports: 8 Imported by: 0

README

citium

Go Report Card Build Status Coverage Status

Serverless function to trigger a scheduled HTTP request

Requirements

  • AWS CLI already configured with AdministratorAccess permission IAM Admin
  • AWS SAM CLI installed SAM CLI

Setup process

Building

Compile binary function:

make build
Packaging & Deployment

Prepare a S3 bucket to upload the binary Lambda function:

aws s3 mb s3://citium-builds --profile adminuser

Package Lambda function to S3:

sam package \
    --template-file template.yaml \
    --s3-bucket citium-builds \
    --output-template-file template.output.yaml \
    --profile adminuser

The returned file template.output.yaml now should contain the CodeUri that points to the artifact to be deployed.

Create a Cloudformation Stack and deploy SAM resources:

sam deploy \
    --template-file template.output.yaml \
    --stack-name citium-serverless \
    --capabilities CAPABILITY_IAM \
    --profile adminuser

After the deployment is complete, run the following command to retrieve stack info:

aws cloudformation describe-stacks --stack-name citium-serverless

The dynamodb table name for storing requests is citium_schedule which could be overridden at packing step.

...
Parameters:
  ScheduleTableName:
    Type: String
    Description: Name of the dynamodb table to be created & used by function
    Default: citium_schedule

Default checking interval is 5 minutes.

...
      Events:
        PeriodicCheck:
          Type: Schedule
          Properties:
            Schedule: rate(5 minutes)
Local development

Invoking function locally

sam local invoke TriggerAPIFunction  --no-event --env-vars env.json --debug

NOTE: Template file should be modified before hand with added property CodeUri pointing to current dir

...
  TriggerAPIFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./
      Handler: citium 

Usage

Build CLI tool

Compile cli tool to schedule requests:

make build-tools
Schedule New Request

If persistent=false then the scheduled request will be removed after successfully executed:

./citium-cli \
    -action=create \
    -table=citium_schedule \
    -id=test-post-request \
    -freeze=30m \
    -method=POST \
    -url=http://example.com \
    -headers=Content-Type:application/json \
    -persistent=true
Lock Request

To safely halt request execution, for the case of execution failure that needs manual intervention:

./citium-cli \
    -action=unlock \
    -table=citium_schedule \
    -id=test-delete-resource
Unlock Request

To release the execution lock:

./citium-cli \
    -action=lock \
    -table=citium_schedule \
    -id=test-delete-resource

Extra options

Optional extra values for API request authorization, base url, etc are configured via environment variables:

...
    Environment:
      Variables:
        TABLE_NAME: !Ref ScheduleTableName
        BASE_URL: ""
        API_TOKEN: ""
        USER_AGENT: citium/0.0.1

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package main provides cli commands to perform basic administrative operations on ScheduledRequest record
Package main provides cli commands to perform basic administrative operations on ScheduledRequest record

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL