Skip to content

Cache un/encrypted expiring values as AWS SSM parameters with a TTL

License

Notifications You must be signed in to change notification settings

CribAdvisor/ssmcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ssmcache

Cache un/encrypted expiring values as AWS SSM parameters with a TTL

Usage

Docs

import (
    "log"

    "github.com/CribAdvisor/ssmcache"
)

func main() {
    cache := ssmcache.New(&ssmcache.SSMCacheOptions{
        Secret: true,
        BasePath: "/cache",
        KeyId: nil,
    })

    accessToken, err := cache.Get("my_token")
    if err != nil {
        log.Fatal(err)
    }
    if accessToken == nil {
        // obtain a new token
        // newToken, ttl := getNewToken(...)
        accessToken = newToken
        cache.Set("my_token", accessToken, ttl)
    }
}

Required IAM permissions

NOTE:

  1. Replace Resource with your AWS region and account ID
  2. Replace /cache with the modified BasePath if applicable
  3. Add kms:Encrypt and kms:Decrypt actions and resources for your KMS key (if applicable)
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1585412677747",
      "Action": [
        "ssm:DeleteParameter",
        "ssm:GetParameter",
        "ssm:PutParameter"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:ssm:<region>:<account_ID>:parameter/cache/*"
    }
  ]
}

About

Cache un/encrypted expiring values as AWS SSM parameters with a TTL

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages