Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.
/ spotmatch Public archive

Lambda function for ensuring a Spot ASG maintains desired capacity by falling back to capacity in On-Demand group

Notifications You must be signed in to change notification settings

ministrycentered/spotmatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spotmatch

Lambda function for ensuring a Spot ASG maintains desired capacity by falling back to capacity in On-Demand group

Run locally with SAM (requires real ASGs specified in event.json)

sam local invoke --event event.json --profile myawsprofile

Package with SAM

sam package --template-file template.yml --s3-bucket mysamartifactss3bucket --output-template-file packaged.yml --profile myawsprofile

The output of sam package includes a CloudFormation template. Use this template in a new CloudFormation stack and you're good to go!

Deploy

Launch stack in us-east-1

Usage

The CloudFormation stack exports a global SpotMatchFunction that you can import with ImportValue into other stacks. From another CloudFormation template, setup a recurring task that runs every minute to verify capacity is met.

OnDemandServerGroup and SpotServerGroup are references to ASGs elsewhere in the template.

SpotMatchRecurringTask:
  Type: AWS::Events::Rule
  Properties:
    Description: Ensure ASGs contain desired capacity
    ScheduleExpression: rate(1 minute)
    State: ENABLED
    Targets:
        - Arn: !Join ['', ['arn:aws:lambda:us-east-1:569307328219:function:', !ImportValue SpotMatchFunction, ':live']]
          Id: spotmatch-recurring-task
          Input: !Sub '{"SpotASGName": "${SpotServerGroup}", "OnDemandASGName":"${OnDemandServerGroup}"}'
PermissionForEventsToInvokeSpotMatchLambdaFunction:
  Type: AWS::Lambda::Permission
  Properties:
    FunctionName: !Join ['', ['arn:aws:lambda:us-east-1:569307328219:function:', !ImportValue SpotMatchFunction, ':live']]
    Action: lambda:InvokeFunction
    Principal: events.amazonaws.com
    SourceArn: !GetAtt SpotMatchRecurringTask.Arn

About

Lambda function for ensuring a Spot ASG maintains desired capacity by falling back to capacity in On-Demand group

Resources

Stars

Watchers

Forks

Packages

No packages published