Giter VIP home page Giter VIP logo

ssm-ps-demo's Introduction

ssm-ps-demo

This repository is part of a Medium article showing a rudimentary example demonstrating how developers can make use of AWS Systems Manager Parameter Store with AWS Lambda (Python 3.9). This includes two handlers meant to be deployed in AWS Lambda.

Requirements

  • Python 3.9
  • AWS SAM CLI
  • Access to consoles for AWS Lambda, IAM, and Systems Manager Parameter Store.
  • Poetry

Development

Install the project from the root.

# If you don't have Poetry globally installed yet.
python3 -m pip install poetry
poetry config virtualenvs.in-project true --local

# Install the project.
poetry install .

This should install any dependency, including boto3. If you're not familiar with Poetry, head on to their website. To view dependencies, see pyproject.toml.

Linting

This project uses black and isort for linting. Run them as below.

poetry run black ./ssm_ps_demo
poetry run isort ./ssm_ps_demo

AWS

The packaging and deployment process should be the same if the project had dependencies or if it were to be deployed as an AWS Lambda layer.

Packaging

Install the project for AWS Lambda deployment from the root. This will create the deployment package as package/ssm-ps-demo.zip.

# Install the project to ./.install/.
pip3 install --target ./package .

# Archive the installation for deployment.
(cd ./package/ && zip -rm ssm-ps-demo.zip .)

Below is the shape of the deployment package.

ssm-ps-demo.zip
├── ssm_ps_demo
│         ├── __init__.py
│         ├── __pycache__
│         │         ├── __init__.cpython-39.pyc
│         │         ├── consumer.cpython-39.pyc
│         │         └── store.cpython-39.pyc
│         ├── consumer.py
│         └── store.py
└── ssm_ps_demo-0.1.0.dist-info
    ├── INSTALLER
    ├── LICENSE
    ├── METADATA
    ├── RECORD
    ├── REQUESTED
    ├── WHEEL
    └── direct_url.json

Deployment

Upload the ssm-ps-demo.zip archive to your AWS Lambda function. See Deploy your .zip file to the function .

When deploying the project to Lambda, you'll have to update the function handlers and environment variables. You can find the design in the medium article .

Path Handler Environment Variable Value IAM Policy
ssm_ps_demo/store.py ssm_ps_demo.store.handler - - See Store IAM Policy.
ssm_ps_demo/consumer.py ssm_ps_demo.consumer.handler STORE_FN_ARN The ARN of the store function. See Consumer IAM Policy.

IAM Policies

On top of the basic execution policies for the deployed functions, they will require additional permissions as below. Replace the *** masks with your AWS region and account number respectively.

Store Function

IAM policy for the store function.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:DescribeParameters"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameters"
      ],
      "Resource": "arn:aws:ssm:***:***:parameter/*"
    }
  ]
}
Consumer Function

IAM policy for the consumer functions.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PermissionToInvoke",
      "Effect": "Allow",
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:***:***:function:smps-store-fn"
    }
  ]
}

AWS SAM

This project includes templates in the sam directory for use with the AWS SAM CLI. Provide your AWS region and credentials in the sam/*.yml files before running the commands below.

# Invoke the store function handler.
sam local invoke --template ./sam/template-store.yml --event ./sam/event.json

# Invoke the consumer function handler.
sam local invoke --template ./template-consumer.yml --no-event

References

ssm-ps-demo's People

Contributors

kdico avatar

Watchers

 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.