Coder Social home page Coder Social logo

secrets-aws-parameter-store's Introduction

Demo SSM Parameter Store Secure String with Cloudformation

Environment variables to deploy the demo stack

INFRA_STACK_NAME=demo
ENVIRONMENT=dev
KMS_KEY_ALIAS=KmsKeyAlias
REGION=us-east-1

Deploy Kms Key stack for encryption secret strings in parameter store

aws cloudformation create-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-kms-key \
	--template-body file://./kms-key.yml \
	--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
	--parameters \
	ParameterKey=KmsKeyAlias,ParameterValue=$KMS_KEY_ALIAS 

AWS doesn't allow the creation of secret string variables via Cloudformation, however we can use a lambda function as a custom resource that will allow us to create these secrets:

aws cloudformation create-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-cr-ssm-helper \
	--template-body file://./cr-ssm-helper.yml \
	--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \

Create secret variables for Dev Environment

# Dev Environment

ENVIRONMENT=dev
aws cloudformation create-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-ssm-variables-backend \
	--template-body file://./ssm-variables-backend.yml \
	--parameters \
	ParameterKey=Environment,ParameterValue=$ENVIRONMENT \
	ParameterKey=KmsKeyAlias,ParameterValue=$KMS_KEY_ALIAS 

Create secret variables for Prod Environment

# Prod Environment

ENVIRONMENT=prod
aws cloudformation create-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-ssm-variables-backend-prod \
	--template-body file://./ssm-variables-backend.yml \
	--parameters \
	ParameterKey=Environment,ParameterValue=$ENVIRONMENT \
	ParameterKey=KmsKeyAlias,ParameterValue=$KMS_KEY_ALIAS 

Query environment variables by path

CONFIG_ENV="/backend/$ENVIRONMENT/"
aws ssm get-parameters-by-path \
    --path $CONFIG_ENV \
    --query 'Parameters[*].[Name,Value]' \
    --with-decryption \
    --region $REGION \
    --output text | \
	awk -F ' ' '{print $1"="$2}' | \
	sed -e "s|$CONFIG_ENV||g"

Query environment variables as environment variables

aws ssm get-parameters-by-path \
    --path $CONFIG_ENV \
    --query 'Parameters[*].[Name,Value]' \
    --with-decryption \
    --region $REGION \
    --output text | \
	awk -F ' ' '{print $1"="$2}' | \
	sed -e "s|$CONFIG_ENV||g" | \
	while read var; do export $var; done

Generate a spreadsheet report in excel format

cd parameter-store-report
DOCKER_IMAGE="parameter-store-report"
docker image rm $DOCKER_IMAGE || (echo "Image $DOCKER_IMAGE didn't exist so not removed."; exit 0)
docker build . -t $DOCKER_IMAGE
docker run --rm -v $HOME/.aws/credentials:/root/.aws/credentials:ro -v $(pwd):/app/output $DOCKER_IMAGE

Example report

Delete cloudformation stack

aws cloudformation delete-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-ssm-variables-backend-prod

aws cloudformation delete-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-ssm-variables-backend

aws cloudformation delete-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-cr-ssm-helper

aws cloudformation delete-stack \
    --region $REGION \
	--stack-name $INFRA_STACK_NAME-kms-key

secrets-aws-parameter-store's People

Contributors

cgn170 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.