Defining Tables, Views, and Indexes in AWS CloudFormation

做~自己de王妃 提交于 2019-12-12 13:13:28

问题


In AWS CloudFormation, you can define a stack of services with a JSON/YAML template. In particular, I am using Redshift and Aurora clusters.

The template allows you to define administrative properties of the cluster, but there doesn't seem to be a clear way to define tables, views, and indexes in the cluster such that when I push updates of stack, the DB's automatically update the schema as needed, similar to the way it manages updates to full stacks.

Is there a way to manage the schema of Redshift and Aurora databases in Cloud Formation?


回答1:


Amazon CloudFormation can be used to create AWS resources. Think of it as calling the standard AWS APIs on your behalf.

Where the 'contents' of a resource can be controlled by an AWS API call, CloudFormation can also manage it. For example, creating a table in Amazon DynamoDB, a bucket in Amazon S3 and a stream in Amazon Kinesis. These are examples of services that are region-wide and fully provided by AWS.

In contrast, where a service must be deployed within an Availability Zone, CloudFormation has no access. Examples are: Amazon EC2 instances, Amazon RDS instances, Amazon Redshift clusters, Amazon EMR clusters and Amazon Elasticsearch clusters. They all run on top of a virtual machine and the 'contents' are not accessible by AWS API calls.

The only way to perform automatic actions in such systems is to call them directly. For example, establishing a JDBC connection to a database and then passing some SQL commands. This could be done from an application running on an Amazon EC2 instance, from an AWS Lambda function or from any computer connected to the Internet.

Amazon CloudFormation can trigger an AWS Lambda-backed Custom Resources. This Lambda function could then perform practically any function, but you would be responsible for coding this function.




回答2:


Work in Progess!! I'll update once I am sure that it is working!

So crawling documentation, Github and an hour on chat with AWS yields that I might need to create a parent and child stack (example templates). The parent stack would contain a SNS Topic, SNS Subscription and Lambda Function that monitor the child stack.

A parent stack might look like,

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  StackEventTopic:
    Type: AWS::SNS::Topic

  StackEventEmailSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: email
      Endpoint: <your email>@gmail.com
      TopicArn:
        Ref: StackEventTopic

  StackEventLambdaSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Protocol: lambda
      Endpoint:
        Ref: StackEventHandler
      TopicArn:
        Ref: StackEventTopic

  StackEventHandler:
    Type: AWS::Lambda::Function
    Properties:
      ... configure your Lambda ...

  ChildStack:
    Type: AWS::CloudFormation::Stack
    Properties:
      NotificationARNs:
        Ref: StackEventTopic
      TemplateURL: "s3 url for template YAML"


来源:https://stackoverflow.com/questions/45553456/defining-tables-views-and-indexes-in-aws-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!