Francis Lewis
Francis Lewis

Reputation: 8980

How do you insert values into dynamodb through cloudformation?

I'm creating a table in cloudformation:

"MyStuffTable": {
    "Type": "AWS::DynamoDB::Table",
    "Properties": {
        "TableName": "MyStuff"
        "AttributeDefinitions": [{
            "AttributeName": "identifier",
            "AttributeType": "S"
        ]},
        "KeySchema": [{
            "AttributeName": "identifier",
            "KeyType": "HASH",
        }],
        "ProvisionedThroughput": {
            "ReadCapacityUnits": "5",
            "WriteCapacityUnits": "1"
         }
    }
}

Then later on in the cloudformation, I want to insert records into that table, something like this:

identifier: Stuff1
data: {My list of stuff here}

And insert that into values in the code below. I had seen somewhere an example that used Custom::Install, but I can't find it now, or any documentation on it. So this is what I have:

MyStuff: {
    "Type": "Custom::Install",
    "DependsOn": [
        "MyStuffTable"
      ],
    "Properties": {
        "ServiceToken": {
            "Fn::GetAtt": ["MyStuffTable","Arn"]
        },
        "Action": "fields",
        "Values": [{<insert records into this array}]
    }
};

When I run that, I'm getting this Invalid service token. So I'm not doing something right trying to reference the table to insert the records into. I can't seem to find any documentation on Custom::Install, so I don't know for sure that it's the right way to go about inserting records through cloudformation. I also can't seem to find documentation on inserting records through cloudformation. I know it can be done. I'm probably missing something very simple. Any ideas?

Upvotes: 0

Views: 1051

Answers (1)

Marcin
Marcin

Reputation: 238189

Custom::Install is a Custom Resource in CloudFormation.

This is a special type of resource which you have to develop yourself. This is mostly done by means of Lambda Function (can also be SNS).

So to answer your question. To add data to your table, you would have to write your own custom resource in lambda. The lambda would put records into the table.

Action and fields are custom parameters which CloudFormation passes to the lambda in the example of Custom::Install. The parameters can be anything you want, as you are designing the custom resource tailored to your requirements.

Upvotes: 2

Related Questions