Giter Site home page Giter Site logo

cloudformation-custom-resource-add-item-to-dynamodb-table's Introduction

A CloudFormation Custom Resource to add an item to a DynamoDB table (CFNDDBAddItem)

Purpose

This project contains an AWS CloudFormation custom resource to add an item to a DynamoDB Table and a Python script that exports items from a source DDB table into a CloudFormation template that references the custom resource.

Requirements

CFNDDAddItem Custom Resource

Deploying CFNDDBAddItem

From the command line, run:

sam build -t cfn-additem-custom_resource_template.yml
sam deploy  --template-file .aws-sam/build/template.yaml --stack-name cfn-dynamodb-add-item  --capabilities "CAPABILITY_NAMED_IAM" --resolve-s3

This will deploy an AWS Lambda custom resource that can be called by your CloudFormation template.

Using the custom resource

  AddItemToDDB:
    Type: Custom::CFNDDBAddItem
    Properties:
      ServiceToken: !ImportValue CFNDDBAddItem
      TableName: ExampleTable
      Item: >
        {
            "year" : 2013,
            "title" : "Turn It Down, Or Else!",
            "info" : {
                "directors" : [
                    "Alice Smith",
                    "Bob Jones"
                ],
                "release_date" : "2013-01-18T00:00:00Z",
                "rating" : 6.2,
                "genres" : [
                    "Comedy",
                    "Drama"
                ],
                "image_url" : "http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg",
                "plot" : "A rock band plays their music at high volumes, annoying the neighbors.",
                "rank" : 11,
                "running_time_secs" : 5215,
                "actors" : [
                    "David Matthewman",
                    "Ann Thomas",
                    "Jonathan G. Neff"
              ]
            }
        }

A sample template is included that creates a DynamoDB table and adds an item to it. You can deploy the sample stack by running:

sam deploy  --template-file sample-cfn-ddb-add-item-template.yml --stack-name cfn-dynamodb-sample-stack  --capabilities "CAPABILITY_NAMED_IAM" --resolve-s3

DynamoDB Exporter script

If you have items in a source DynamoDB table that you want to import into a separate DynamoDB table, you can use the create-dynamo-items-template Python script.

Usage

First create a config.json file in the dynamodb_exporter directory:

{
    "TableName":"your source DynamoDB table",
    "Output":{
        "Filename": "output-template.json",
        "TableName":"destination DynamoDB table",
        "TemplateDescription":"A description of the stack that wlll be created."
    }
}

Then run the script:

cd dynamodb_exporter    
pip3 install -r requirements.txt #First time only
python3 ./dynamodb-exporter/create-dynamodb-items-template.py

cloudformation-custom-resource-add-item-to-dynamodb-table's People

Contributors

amazon-auto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

karldthomas

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.