Amazon Relational Database Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
* [[PostgreSQL Operations]]
* [[PostgreSQL Operations]]


=Create a Database Instance with CloudFormation=
=Create a Database=
==AWS::RDS::DBInstance==
==Create a Database Instance with CloudFormation==
===AWS::RDS::DBInstance===
{{External|[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html AWS::RDS::DBInstance]}}
{{External|[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html AWS::RDS::DBInstance]}}


Line 33: Line 34:
For details on DBSubnetGroupName and VPCSecurityGroups, see: {{Internal|Deploying a RDS Instance into a Specific VPC|Deploying a RDS Instance into a Specific VPC}}
For details on DBSubnetGroupName and VPCSecurityGroups, see: {{Internal|Deploying a RDS Instance into a Specific VPC|Deploying a RDS Instance into a Specific VPC}}


===Return Values===
====Return Values====


====Ref====
=====Ref=====


Returns [[Amazon_Relational_Database_Concepts#Instance_Identifier|instance identifier]] (DBInstanceIdentifier).
Returns [[Amazon_Relational_Database_Concepts#Instance_Identifier|instance identifier]] (DBInstanceIdentifier).
====GetAtt====
=====GetAtt=====


* Endpoint.Address returns the connection endpoint for the database (e.g. mystack-mydb-1apw1j4phylrk.cg034hpkmmjt.us-east-2.rds.amazonaws.com)
* Endpoint.Address returns the connection endpoint for the database (e.g. mystack-mydb-1apw1j4phylrk.cg034hpkmmjt.us-east-2.rds.amazonaws.com)
* Endpoint.Port
* Endpoint.Port


===Examples===
====Examples====


====PostgreSQL====
=====PostgreSQL=====
<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='yaml'>
Resources
Resources
Line 72: Line 73:
</syntaxhighlight>
</syntaxhighlight>


====SQL Server====
=====SQL Server=====
<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='yaml'>
</syntaxhighlight>
</syntaxhighlight>


==AWS::RDS::DBSubnetGroup==
===AWS::RDS::DBSubnetGroup===


{{External|[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbsubnet-group.html AWS::RDS::DBSubnetGroup]}}
{{External|[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbsubnet-group.html AWS::RDS::DBSubnetGroup]}}

Revision as of 02:13, 9 September 2020

Internal

Create a Database

Create a Database Instance with CloudFormation

AWS::RDS::DBInstance

AWS::RDS::DBInstance
Resources:
  PostgresDBInstance: 
  Type: AWS::RDS::DBInstance
  DeletionPolicy: Delete
  Properties: 
    DBName: themyscira01
    DBInstanceIdentifier: !Sub ${EnvironmentName}-${MicroworldName}-postgres
    AllocatedStorage: 8
    DBInstanceClass: db.t2.micro
    Engine: postgres
    EngineVersion: 9.4.20
    MasterUsername: bn73hewc
    MasterUserPassword: ce75h9w0
    #
    # This is what configures the DB instance to be deployed in a specific VPC. See VPC Association.
    #
    DBSubnetGroupName: !Ref PostgresSubnetGroup
    VPCSecurityGroups:
      - !Ref PostgresSecurityGroup
    Tags: 
      - Key: Name
        Value: !Sub ${EnvironmentName}-${MicroworldName}-postgres

For details on DBSubnetGroupName and VPCSecurityGroups, see:

Deploying a RDS Instance into a Specific VPC

Return Values

Ref

Returns instance identifier (DBInstanceIdentifier).

GetAtt
  • Endpoint.Address returns the connection endpoint for the database (e.g. mystack-mydb-1apw1j4phylrk.cg034hpkmmjt.us-east-2.rds.amazonaws.com)
  • Endpoint.Port

Examples

PostgreSQL
Resources
  PostgresDBInstance:
    Type: AWS::RDS::DBInstance
    DeletionPolicy: Delete
    Properties:
      #
      # We create just the first database of the environment, if we need more, we need to create them
      # interactively, as CloudFormation does not support this
      #
      DBName: !Ref FirstPostgresDatabaseName
      DBInstanceIdentifier: !Sub ${EnvironmentName}-${MicroworldName}-postgres
      AllocatedStorage: 8
      DBInstanceClass: db.t2.micro
      Engine: postgres
      EngineVersion: 9.4.20
      MasterUsername: !Ref PostgreSQLUsername
      MasterUserPassword: !Ref PostgreSQLPassword
      DBSubnetGroupName: !Ref PostgresSubnetGroup
      VPCSecurityGroups:
        - !Ref PostgresSecurityGroup
      Tags:
        - Key: Name
          Value: !Sub ${EnvironmentName}-${MicroworldName}-postgres
SQL Server

AWS::RDS::DBSubnetGroup

AWS::RDS::DBSubnetGroup
Resources:
  PostgresSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
      DBSubnetGroupDescription: !Sub The subnet group used by the ${MicroworldName}/${EnvironmentName} environment PostgreSQL instance
      DBSubnetGroupName: !Sub ${MicroworldName}-${EnvironmentName}-postgres-subnet-group
      SubnetIds:
        - !Ref PostgresSubnet1
        - !Ref PostgresSubnet2
      Tags:
        - Key: Name
          Value: !Sub ${MicroworldName}-${EnvironmentName}-postgres-subnet-group

Deploying a RDS Instance into a Specific VPC

Deploying a RDS Instance into a Specific VPC

PostgreSQL Operations

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html
psql --host=test-rds-01.asxqzuh7ivbrb.us-east-1.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=postgres

More details:

PostgreSQL Operations