From 7d017c68c277871648b2129ad987277f30257096 Mon Sep 17 00:00:00 2001 From: Keep Focused Date: Thu, 2 Jan 2025 15:44:11 +0700 Subject: [PATCH] Add aws_keyspaces_keyspace and aws_keyspaces_table tables Closes #2264 (#2271) Co-authored-by: Priyanka Chatterjee --- .../aws_keyspaces_table/dependencies.txt | 0 .../test-get-call-expected.json | 7 + .../test-get-call-query.sql | 3 + .../test-list-call-expected.json | 10 + .../test-list-call-query.sql | 3 + .../test-turbot-expected.json | 8 + .../aws_keyspaces_table/test-turbot-query.sql | 3 + .../tests/aws_keyspaces_table/variables.json | 1 + .../tests/aws_keyspaces_table/variables.tf | 76 +++++ aws/plugin.go | 2 + aws/service.go | 13 + aws/table_aws_keyspaces_keyspace.go | 165 +++++++++++ aws/table_aws_keyspaces_table.go | 266 ++++++++++++++++++ docs/tables/aws_keyspaces_keyspace.md | 106 +++++++ docs/tables/aws_keyspaces_table.md | 193 +++++++++++++ go.mod | 1 + go.sum | 2 + 17 files changed, 859 insertions(+) create mode 100644 aws-test/tests/aws_keyspaces_table/dependencies.txt create mode 100644 aws-test/tests/aws_keyspaces_table/test-get-call-expected.json create mode 100644 aws-test/tests/aws_keyspaces_table/test-get-call-query.sql create mode 100644 aws-test/tests/aws_keyspaces_table/test-list-call-expected.json create mode 100644 aws-test/tests/aws_keyspaces_table/test-list-call-query.sql create mode 100644 aws-test/tests/aws_keyspaces_table/test-turbot-expected.json create mode 100644 aws-test/tests/aws_keyspaces_table/test-turbot-query.sql create mode 100644 aws-test/tests/aws_keyspaces_table/variables.json create mode 100644 aws-test/tests/aws_keyspaces_table/variables.tf create mode 100644 aws/table_aws_keyspaces_keyspace.go create mode 100644 aws/table_aws_keyspaces_table.go create mode 100644 docs/tables/aws_keyspaces_keyspace.md create mode 100644 docs/tables/aws_keyspaces_table.md diff --git a/aws-test/tests/aws_keyspaces_table/dependencies.txt b/aws-test/tests/aws_keyspaces_table/dependencies.txt new file mode 100644 index 000000000..e69de29bb diff --git a/aws-test/tests/aws_keyspaces_table/test-get-call-expected.json b/aws-test/tests/aws_keyspaces_table/test-get-call-expected.json new file mode 100644 index 000000000..86b95bbe3 --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-get-call-expected.json @@ -0,0 +1,7 @@ +[ + { + "akas": ["{{ output.resource_aka.value }}"], + "table_name": "{{resourceName}}", + "title": "{{resourceName}}" + } +] diff --git a/aws-test/tests/aws_keyspaces_table/test-get-call-query.sql b/aws-test/tests/aws_keyspaces_table/test-get-call-query.sql new file mode 100644 index 000000000..0911842ed --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-get-call-query.sql @@ -0,0 +1,3 @@ +select title, akas, table_name +from aws.aws_keyspaces_table +where keyspace_name = '{{resourceName}}' and table_name = '{{resourceName}}'; diff --git a/aws-test/tests/aws_keyspaces_table/test-list-call-expected.json b/aws-test/tests/aws_keyspaces_table/test-list-call-expected.json new file mode 100644 index 000000000..a2a8257d7 --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-list-call-expected.json @@ -0,0 +1,10 @@ +[ + { + "akas": [ + "{{ output.resource_aka.value }}" + ], + "keyspace_name": "{{resourceName}}", + "table_name": "{{resourceName}}", + "title": "{{resourceName}}" + } +] diff --git a/aws-test/tests/aws_keyspaces_table/test-list-call-query.sql b/aws-test/tests/aws_keyspaces_table/test-list-call-query.sql new file mode 100644 index 000000000..9d26da46b --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-list-call-query.sql @@ -0,0 +1,3 @@ +select table_name, keyspace_name, title, akas +from aws.aws_keyspaces_table +where keyspace_name = '{{ resourceName }}'; diff --git a/aws-test/tests/aws_keyspaces_table/test-turbot-expected.json b/aws-test/tests/aws_keyspaces_table/test-turbot-expected.json new file mode 100644 index 000000000..012744598 --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-turbot-expected.json @@ -0,0 +1,8 @@ +[ + { + "akas": [ + "{{ output.resource_aka.value }}" + ], + "title": "{{resourceName}}" + } +] diff --git a/aws-test/tests/aws_keyspaces_table/test-turbot-query.sql b/aws-test/tests/aws_keyspaces_table/test-turbot-query.sql new file mode 100644 index 000000000..f01537367 --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/test-turbot-query.sql @@ -0,0 +1,3 @@ +select akas, title +from aws.aws_keyspaces_table +where keyspace_name = '{{ resourceName }}'; diff --git a/aws-test/tests/aws_keyspaces_table/variables.json b/aws-test/tests/aws_keyspaces_table/variables.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/variables.json @@ -0,0 +1 @@ +{} diff --git a/aws-test/tests/aws_keyspaces_table/variables.tf b/aws-test/tests/aws_keyspaces_table/variables.tf new file mode 100644 index 000000000..98e6e7aea --- /dev/null +++ b/aws-test/tests/aws_keyspaces_table/variables.tf @@ -0,0 +1,76 @@ + +variable "resource_name" { + type = string + default = "turbot-test-20200125-create-update" + description = "Name of the resource used throughout the test." +} + +variable "aws_profile" { + type = string + default = "default" + description = "AWS credentials profile used for the test. Default is to use the default profile." +} + +variable "aws_region" { + type = string + default = "us-east-1" + description = "AWS region used for the test. Does not work with default region in config, so must be defined here." +} + +variable "aws_region_alternate" { + type = string + default = "us-east-2" + description = "Alternate AWS region used for tests that require two regions (e.g. DynamoDB global tables)." +} + +provider "aws" { + profile = var.aws_profile + region = var.aws_region +} + +provider "aws" { + alias = "alternate" + profile = var.aws_profile + region = var.aws_region_alternate +} + +data "aws_partition" "current" {} +data "aws_caller_identity" "current" {} +data "aws_region" "primary" {} +data "aws_region" "alternate" { + provider = aws.alternate +} + +data "null_data_source" "resource" { + inputs = { + scope = "arn:${data.aws_partition.current.partition}:::${data.aws_caller_identity.current.account_id}" + } +} + +resource "aws_keyspaces_keyspace" "named_test_resource" { + name = var.resource_name +} + +resource "aws_keyspaces_table" "named_test_resource" { + keyspace_name = aws_keyspaces_keyspace.named_test_resource.name + table_name = var.resource_name + + schema_definition { + column { + name = "test_id" + type = "ascii" + } + + partition_key { + name = "test_id" + } + } +} + +output "resource_aka" { + value = aws_keyspaces_table.named_test_resource.arn +} + +output "resource_name" { + value = var.resource_name +} diff --git a/aws/plugin.go b/aws/plugin.go index dd58c0610..b69775de4 100644 --- a/aws/plugin.go +++ b/aws/plugin.go @@ -356,6 +356,8 @@ func Plugin(ctx context.Context) *plugin.Plugin { "aws_iot_thing": tableAwsIoTThing(ctx), "aws_iot_thing_group": tableAwsIoTThingGroup(ctx), "aws_iot_thing_type": tableAwsIoTThingType(ctx), + "aws_keyspaces_keyspace": tableAwsKeyspacesKeyspace(ctx), + "aws_keyspaces_table": tableAwsKeyspacesTable(ctx), "aws_kinesis_consumer": tableAwsKinesisConsumer(ctx), "aws_kinesis_firehose_delivery_stream": tableAwsKinesisFirehoseDeliveryStream(ctx), "aws_kinesis_stream": tableAwsKinesisStream(ctx), diff --git a/aws/service.go b/aws/service.go index 8e74b0737..97ba3f305 100644 --- a/aws/service.go +++ b/aws/service.go @@ -85,6 +85,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/inspector2" "github.com/aws/aws-sdk-go-v2/service/iot" "github.com/aws/aws-sdk-go-v2/service/kafka" + "github.com/aws/aws-sdk-go-v2/service/keyspaces" "github.com/aws/aws-sdk-go-v2/service/kinesis" "github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2" "github.com/aws/aws-sdk-go-v2/service/kinesisvideo" @@ -179,6 +180,7 @@ import ( inspector2Endpoint "github.com/aws/aws-sdk-go/service/inspector2" iotEndpoint "github.com/aws/aws-sdk-go/service/iot" kafkaEndpoint "github.com/aws/aws-sdk-go/service/kafka" + keyspacesEndpoint "github.com/aws/aws-sdk-go/service/keyspaces" kinesisanalyticsv2Endpoint "github.com/aws/aws-sdk-go/service/kinesisanalyticsv2" kinesisvideoEndpoint "github.com/aws/aws-sdk-go/service/kinesisvideo" kmsEndpoint "github.com/aws/aws-sdk-go/service/kms" @@ -930,6 +932,17 @@ func KafkaClient(ctx context.Context, d *plugin.QueryData) (*kafka.Client, error return kafka.NewFromConfig(*cfg), nil } +func KeyspacesClient(ctx context.Context, d *plugin.QueryData) (*keyspaces.Client, error) { + cfg, err := getClientForQuerySupportedRegion(ctx, d, keyspacesEndpoint.EndpointsID) + if err != nil { + return nil, err + } + if cfg == nil { + return nil, nil + } + return keyspaces.NewFromConfig(*cfg), nil +} + func KinesisClient(ctx context.Context, d *plugin.QueryData) (*kinesis.Client, error) { cfg, err := getClientForQueryRegion(ctx, d) if err != nil { diff --git a/aws/table_aws_keyspaces_keyspace.go b/aws/table_aws_keyspaces_keyspace.go new file mode 100644 index 000000000..f77c0c4f5 --- /dev/null +++ b/aws/table_aws_keyspaces_keyspace.go @@ -0,0 +1,165 @@ +package aws + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/keyspaces" + // "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" + keyspacesv1 "github.com/aws/aws-sdk-go/service/keyspaces" + + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" +) + +//// TABLE DEFINITION + +func tableAwsKeyspacesKeyspace(ctx context.Context) *plugin.Table { + return &plugin.Table{ + Name: "aws_keyspaces_keyspace", + Description: "AWS Keyspaces Keyspace", + Get: &plugin.GetConfig{ + KeyColumns: plugin.SingleColumn("keyspace_name"), // Identify the keyspace by its name + Hydrate: getKeyspacesKeyspace, // Get function + IgnoreConfig: &plugin.IgnoreConfig{ + ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), + }, + Tags: map[string]string{"service": "keyspaces", "action": "GetKeyspace"}, + }, + List: &plugin.ListConfig{ + Hydrate: listKeyspacesKeyspaces, // Parent hydrate function + Tags: map[string]string{"service": "keyspaces", "action": "ListKeyspaces"}, + }, + GetMatrixItemFunc: SupportedRegionMatrix(keyspacesv1.EndpointsID), + Columns: awsRegionalColumns([]*plugin.Column{ + { + Name: "keyspace_name", + Description: "The name of the keyspace.", + Type: proto.ColumnType_STRING, + }, + { + Name: "arn", + Description: "The unique identifier of the keyspace in the format of an Amazon Resource Name (ARN).", + Type: proto.ColumnType_STRING, + Transform: transform.FromField("ResourceArn"), + }, + { + Name: "replication_strategy", + Description: "Returns the replication strategy of the keyspace. The options are SINGLE_REGION or MULTI_REGION .", + Type: proto.ColumnType_STRING, + }, + { + Name: "replication_regions", + Description: "If the replication strategy of the keyspace is MULTI_REGION, a list of replication regions is returned.", + Type: proto.ColumnType_JSON, + }, + + /// Steampipe standard columns + { + Name: "title", + Description: resourceInterfaceDescription("title"), + Type: proto.ColumnType_STRING, + Transform: transform.FromField("KeyspaceName"), + }, + { + Name: "akas", + Description: resourceInterfaceDescription("akas"), + Type: proto.ColumnType_JSON, + Transform: transform.FromField("ResourceArn").Transform(transform.EnsureStringArray), + }, + }), + } +} + +//// LIST FUNCTION + +func listKeyspacesKeyspaces(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { + // Create session + svc, err := KeyspacesClient(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_keyspace.listKeyspacesKeyspaces", "connection_error", err) + return nil, err + } + + if svc == nil { + // Unsupported region check + return nil, nil + } + + // Define max results for the request + maxItems := int32(1000) + if d.QueryContext.Limit != nil { + limit := int32(*d.QueryContext.Limit) + if limit < maxItems { + maxItems = limit + } + } + + input := &keyspaces.ListKeyspacesInput{ + MaxResults: &maxItems, + } + + paginator := keyspaces.NewListKeyspacesPaginator(svc, input, func(o *keyspaces.ListKeyspacesPaginatorOptions) { + o.Limit = maxItems + o.StopOnDuplicateToken = true + }) + + for paginator.HasMorePages() { + // apply rate limiting + d.WaitForListRateLimit(ctx) + + output, err := paginator.NextPage(ctx) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_keyspace.listKeyspacesKeyspaces", "api_error", err) + return nil, err + } + + for _, keyspace := range output.Keyspaces { + d.StreamListItem(ctx, keyspace) + + // Stop processing if context is canceled or limit is reached + if d.RowsRemaining(ctx) == 0 { + return nil, nil + } + } + } + + return nil, nil +} + +//// GET FUNCTION + +func getKeyspacesKeyspace(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { + keyspaceName := d.EqualsQualString("keyspace_name") + + // Empty check for keyspace name + if keyspaceName == "" { + return nil, nil + } + + // Create session + svc, err := KeyspacesClient(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_keyspace.getKeyspacesKeyspace", "connection_error", err) + return nil, err + } + + if svc == nil { + // Unsupported region + return nil, nil + } + + // Build the input parameters + input := &keyspaces.GetKeyspaceInput{ + KeyspaceName: &keyspaceName, + } + + // Make the GetKeyspace API call + result, err := svc.GetKeyspace(ctx, input) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_keyspace.getKeyspacesKeyspace", "api_error", err) + return nil, err + } + + return result, nil +} diff --git a/aws/table_aws_keyspaces_table.go b/aws/table_aws_keyspaces_table.go new file mode 100644 index 000000000..d4f41abef --- /dev/null +++ b/aws/table_aws_keyspaces_table.go @@ -0,0 +1,266 @@ +package aws + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/keyspaces" + "github.com/aws/aws-sdk-go-v2/service/keyspaces/types" + keyspacesv1 "github.com/aws/aws-sdk-go/service/keyspaces" + + "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin" + "github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" +) + +//// TABLE DEFINITION + +func tableAwsKeyspacesTable(ctx context.Context) *plugin.Table { + return &plugin.Table{ + Name: "aws_keyspaces_table", + Description: "AWS Keyspaces Table", + Get: &plugin.GetConfig{ + KeyColumns: plugin.AllColumns([]string{"keyspace_name", "table_name"}), + Hydrate: getKeyspacesTable, + IgnoreConfig: &plugin.IgnoreConfig{ + ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), + }, + Tags: map[string]string{"service": "keyspaces", "action": "GetTable"}, + }, + List: &plugin.ListConfig{ + ParentHydrate: listKeyspacesKeyspaces, // Call parent hydrate + Hydrate: listKeyspacesTables, // Child list function + KeyColumns: plugin.KeyColumnSlice{ + {Name: "keyspace_name", Require: plugin.Optional}, + }, + Tags: map[string]string{"service": "keyspaces", "action": "ListTables"}, + }, + HydrateConfig: []plugin.HydrateConfig{ + { + Func: getKeyspacesTable, + Tags: map[string]string{"service": "keyspaces", "action": "GetTable"}, + }, + }, + GetMatrixItemFunc: SupportedRegionMatrix(keyspacesv1.EndpointsID), + Columns: awsRegionalColumns([]*plugin.Column{ + { + Name: "keyspace_name", + Description: "The name of the keyspace that the table is stored in.", + Type: proto.ColumnType_STRING, + }, + { + Name: "table_name", + Description: "The name of the table.", + Type: proto.ColumnType_STRING, + }, + { + Name: "arn", + Description: "The unique identifier of the table in the format of an Amazon Resource Name (ARN).", + Type: proto.ColumnType_STRING, + Transform: transform.FromField("ResourceArn"), + }, + { + Name: "status", + Description: "The current status of the specified table.", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + }, + { + Name: "ttl_status", + Description: "The custom Time to Live settings of the specified table.", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + Transform: transform.FromField("Ttl.Status"), + }, + { + Name: "client_side_timestamps_status", + Description: "Shows how to enable client-side timestamps settings for the specified table.", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + Transform: transform.FromField("ClientSideTimestamps.Status"), + }, + { + Name: "creation_timestamp", + Description: "The creation timestamp of the specified table.", + Type: proto.ColumnType_TIMESTAMP, + Hydrate: getKeyspacesTable, + }, + { + Name: "default_time_to_live", + Description: "The default Time to Live settings in seconds of the specified table.", + Type: proto.ColumnType_INT, + Hydrate: getKeyspacesTable, + }, + { + Name: "comment_message", + Description: "An optional description of the table.", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + Transform: transform.FromField("Comment.Message"), + }, + { + Name: "encryption_specification_type", + Description: "The encryption option specified for the table.", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + Transform: transform.FromField("EncryptionSpecification.Type"), + }, + { + Name: "kms_key_identifier", + Description: "The Amazon Resource Name (ARN) of the customer managed KMS key,", + Type: proto.ColumnType_STRING, + Hydrate: getKeyspacesTable, + Transform: transform.FromField("EncryptionSpecification.KmsKeyIdentifier"), + }, + { + Name: "point_in_time_recovery", + Description: "The point-in-time recovery status of the specified table.", + Type: proto.ColumnType_JSON, + Hydrate: getKeyspacesTable, + }, + { + Name: "capacity_specification", + Description: "The read/write throughput capacity mode for a table.", + Type: proto.ColumnType_JSON, + Hydrate: getKeyspacesTable, + }, + { + Name: "replica_specifications", + Description: "Returns the Amazon Web Services Region specific settings of all Regions a multi-Region table is replicated in.", + Type: proto.ColumnType_JSON, + Hydrate: getKeyspacesTable, + }, + { + Name: "schema_definition", + Description: "The schema definition of the specified table.", + Type: proto.ColumnType_JSON, + Hydrate: getKeyspacesTable, + }, + + /// Steampipe standard columns + { + Name: "title", + Description: resourceInterfaceDescription("title"), + Type: proto.ColumnType_STRING, + Transform: transform.FromField("TableName"), + }, + { + Name: "akas", + Description: resourceInterfaceDescription("akas"), + Type: proto.ColumnType_JSON, + Transform: transform.FromField("ResourceArn").Transform(transform.EnsureStringArray), + }, + }), + } +} + +//// LIST FUNCTION + +func listKeyspacesTables(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + var keySpaceName string + if h.Item != nil { + keySpaceName = *h.Item.(types.KeyspaceSummary).KeyspaceName + } + + // Limit API call with given Keyspace Name + if d.EqualsQualString("keyspace_name") != "" && d.EqualsQualString("keyspace_name") != keySpaceName { + return nil, nil + } + + // Create Session + svc, err := KeyspacesClient(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_table.listKeyspacesTables", "connection_error", err) + return nil, err + } + + if svc == nil { + // Unsupported region check + return nil, nil + } + + maxItems := int32(1000) + + // Reduce the basic request limit down if the user has only requested a small number of rows + if d.QueryContext.Limit != nil { + limit := int32(*d.QueryContext.Limit) + if limit < maxItems { + + maxItems = limit + } + } + + input := &keyspaces.ListTablesInput{ + MaxResults: &maxItems, + KeyspaceName: &keySpaceName, + } + + paginator := keyspaces.NewListTablesPaginator(svc, input, func(o *keyspaces.ListTablesPaginatorOptions) { + o.Limit = maxItems + o.StopOnDuplicateToken = true + }) + + for paginator.HasMorePages() { + // apply rate limiting + d.WaitForListRateLimit(ctx) + + output, err := paginator.NextPage(ctx) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_table.listKeyspacesTables", "api_error", err) + return nil, err + } + + for _, keyspace := range output.Tables { + d.StreamListItem(ctx, keyspace) + + // Stop processing if context is canceled or limit is reached + if d.RowsRemaining(ctx) == 0 { + return nil, nil + } + } + } + + return nil, nil +} + +//// HYDRATE FUNCTIONS + +func getKeyspacesTable(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + keyspaceName := d.EqualsQualString("keyspace_name") + tableName := d.EqualsQualString("table_name") + + if h.Item != nil { + keyspaceTable := h.Item.(types.TableSummary) + keyspaceName = *keyspaceTable.KeyspaceName + tableName = *keyspaceTable.TableName + } + + // Empty id check + if keyspaceName == "" || tableName == "" { + return nil, nil + } + + // Create Session + svc, err := KeyspacesClient(ctx, d) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_table.getKeyspacesTable", "connection_error", err) + return nil, err + } + + if svc == nil { + // Unsupported region, return no data + return nil, nil + } + + params := &keyspaces.GetTableInput{ + KeyspaceName: &keyspaceName, + TableName: &tableName, + } + + op, err := svc.GetTable(ctx, params) + if err != nil { + plugin.Logger(ctx).Error("aws_keyspaces_table.getKeyspacesTable", "api_error", err) + return nil, err + } + + return op, nil +} diff --git a/docs/tables/aws_keyspaces_keyspace.md b/docs/tables/aws_keyspaces_keyspace.md new file mode 100644 index 000000000..b13cf3ef0 --- /dev/null +++ b/docs/tables/aws_keyspaces_keyspace.md @@ -0,0 +1,106 @@ +--- +title: "Steampipe Table: aws_keyspaces_keyspace - Query AWS Keyspaces Keyspaces using SQL" +description: "Allows users to query AWS Keyspaces keyspaces, providing detailed information on replication strategies, creation timestamps, and regions." +--- + +# Table: aws_keyspaces_keyspace - Query AWS Keyspaces Keyspaces using SQL + +Amazon Keyspaces (for Apache Cassandra) is a scalable, highly available, and managed Apache Cassandra-compatible database service. It enables you to run Cassandra workloads on AWS without managing the underlying infrastructure. The `aws_keyspaces_keyspace` table in Steampipe allows you to query information about your Keyspaces keyspaces in AWS, including their name, ARN, replication strategy, and other details. + +## Table Usage Guide + +The `aws_keyspaces_keyspace` table enables cloud administrators and DevOps engineers to gather detailed insights into their Keyspaces keyspaces. You can query various aspects of the keyspace, such as its replication strategy, creation timestamp, and replication regions. This table is useful for monitoring keyspaces configurations and ensuring they align with organizational requirements. + +## Examples + +### Basic keyspace information +Retrieve basic information about your AWS Keyspaces keyspaces, including their name, ARN, and region. + +```sql+postgres +select + keyspace_name, + arn, + region +from + aws_keyspaces_keyspace; +``` + +```sql+sqlite +select + keyspace_name, + arn, + region +from + aws_keyspaces_keyspace; +``` + +### List keyspaces by region +Retrieve a list of keyspaces grouped by their region. This is useful for understanding your keyspaces distribution across AWS regions. + +```sql+postgres +select + keyspace_name, + arn, + region +from + aws_keyspaces_keyspace +order by + region; +``` + +```sql+sqlite +select + keyspace_name, + arn, + region +from + aws_keyspaces_keyspace +order by + region; +``` + +### Identify keyspaces with specific replication strategy +Find keyspaces using a specific replication strategy, which can help ensure compliance with replication policies. + +```sql+postgres +select + keyspace_name, + arn, + replication_strategy +from + aws_keyspaces_keyspace +where + replication_strategy = 'SINGLE_REGION'; +``` + +```sql+sqlite +select + keyspace_name, + arn, + replication_strategy +from + aws_keyspaces_keyspace +where + replication_strategy = 'SINGLE_REGION'; +``` + +### List keyspaces with their replication regions +Retrieve a list of keyspaces along with their replication regions to understand where data is being replicated. + +```sql+postgres +select + keyspace_name, + arn, + replication_regions +from + aws_keyspaces_keyspace; +``` + +```sql+sqlite +select + keyspace_name, + arn, + replication_regions +from + aws_keyspaces_keyspace; +``` \ No newline at end of file diff --git a/docs/tables/aws_keyspaces_table.md b/docs/tables/aws_keyspaces_table.md new file mode 100644 index 000000000..c4a998269 --- /dev/null +++ b/docs/tables/aws_keyspaces_table.md @@ -0,0 +1,193 @@ +--- +title: "Steampipe Table: aws_keyspaces_table - Query AWS Keyspaces Tables using SQL" +description: "Allows users to query AWS Keyspaces tables, providing detailed information on table configurations, throughput capacity, encryption, and more." +--- + +# Table: aws_keyspaces_table - Query AWS Keyspaces Tables using SQL + +Amazon Keyspaces (for Apache Cassandra) is a scalable, highly available, and managed Apache Cassandra-compatible database service. It enables you to run Cassandra workloads on AWS without managing the underlying infrastructure. The `aws_keyspaces_table` table in Steampipe allows you to query information about your Keyspaces tables in AWS, including their capacity specifications, encryption settings, and schema definitions. + +## Table Usage Guide + +The `aws_keyspaces_table` table enables cloud administrators and DevOps engineers to gather detailed insights into their Keyspaces tables. You can query various aspects of the table, such as its creation timestamp, throughput capacity, encryption, and status. This table is particularly useful for monitoring table performance, ensuring security compliance, and managing table configurations. + +## Examples + +### Basic table information +Retrieve basic information about your AWS Keyspaces tables, including their name, ARN, status, and region. This can be useful for getting an overview of the tables deployed in your AWS account. + +```sql+postgres +select + table_name, + arn, + status, + creation_timestamp, + region +from + aws_keyspaces_table; +``` + +```sql+sqlite +select + table_name, + arn, + status, + creation_timestamp, + region +from + aws_keyspaces_table; +``` + +### List active tables +Fetch a list of tables that are currently active. This can help in identifying which tables are operational and available for use. + +```sql+postgres +select + table_name, + arn, + status +from + aws_keyspaces_table +where + status = 'ACTIVE'; +``` + +```sql+sqlite +select + table_name, + arn, + status +from + aws_keyspaces_table +where + status = 'ACTIVE'; +``` + +### List tables with specific encryption settings +Identify tables that have specific encryption settings, which can help ensure that your data is secured according to your organization’s encryption policies. + +```sql+postgres +select + table_name, + arn, + encryption_specification_type, + kms_key_identifier +from + aws_keyspaces_table +where + encryption_specification_type = 'AWS_OWNED_KMS_KEY'; +``` + +```sql+sqlite +select + table_name, + arn, + encryption_specification_type, + kms_key_identifier +from + aws_keyspaces_table +where + encryption_specification_type = 'AWS_OWNED_KMS_KEY'; +``` + +### List tables by creation date +Retrieve tables ordered by their creation date, which can be useful for auditing purposes or understanding the lifecycle of your Keyspaces tables. + +```sql+postgres +select + table_name, + arn, + creation_timestamp +from + aws_keyspaces_table +order by + creation_timestamp desc; +``` + +```sql+sqlite +select + table_name, + arn, + creation_timestamp +from + aws_keyspaces_table +order by + creation_timestamp desc; +``` + +### List tables with default Time to Live (TTL) settings +Identify tables that have a specific default Time to Live (TTL) setting, which is useful for managing data retention and ensuring compliance with data lifecycle policies. + +```sql+postgres +select + table_name, + arn, + default_time_to_live, + ttl_status +from + aws_keyspaces_table +where + default_time_to_live is not null; +``` + +```sql+sqlite +select + table_name, + arn, + default_time_to_live, + ttl_status +from + aws_keyspaces_table +where + default_time_to_live is not null; +``` + +### Get table schema definitions +Retrieve detailed schema definitions for your Keyspaces tables, which can help in understanding the structure and types of data stored in the tables. + +```sql+postgres +select + table_name, + arn, + schema_definition +from + aws_keyspaces_table +where + keyspace_name = 'myKey'; +``` + +```sql+sqlite +select + table_name, + arn, + schema_definition +from + aws_keyspaces_table +where + keyspace_name = 'myKey'; +``` + +### List tables with Point-in-Time Recovery (PITR) enabled +Identify tables where Point-in-Time Recovery (PITR) is enabled, which is essential for ensuring that you can restore your table to a previous state within a specified timeframe. + +```sql+postgres +select + table_name, + arn, + point_in_time_recovery +from + aws_keyspaces_table +where + (point_in_time_recovery ->> 'status') = 'ENABLED'; +``` + +```sql+sqlite +select + table_name, + arn, + point_in_time_recovery +from + aws_keyspaces_table +where + json_extract(point_in_time_recovery, '$.status') = 'ENABLED'; +``` \ No newline at end of file diff --git a/go.mod b/go.mod index 0a52d95c2..34046cd26 100644 --- a/go.mod +++ b/go.mod @@ -78,6 +78,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/inspector2 v1.24.4 github.com/aws/aws-sdk-go-v2/service/iot v1.53.3 github.com/aws/aws-sdk-go-v2/service/kafka v1.31.2 + github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.8 github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4 github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2 v1.25.2 github.com/aws/aws-sdk-go-v2/service/kinesisvideo v1.23.4 diff --git a/go.sum b/go.sum index 7b7b91be6..63ca7bce4 100644 --- a/go.sum +++ b/go.sum @@ -371,6 +371,8 @@ github.com/aws/aws-sdk-go-v2/service/iot v1.53.3 h1:d9R8dezHswXV9am8Sz+1HOsCas1/ github.com/aws/aws-sdk-go-v2/service/iot v1.53.3/go.mod h1:7rtIbAvSP5Nbc1f7sbeWa+uMV+T6khOkWAh6VHsbOZI= github.com/aws/aws-sdk-go-v2/service/kafka v1.31.2 h1:jODSVa9LbXmZKRLy4KLFHCfhKlCGzU8FPOClKTqrh9U= github.com/aws/aws-sdk-go-v2/service/kafka v1.31.2/go.mod h1:ofW8A+AyFHi/MMYwYI5YkJ5h2JWCCtyHR/P7UQONcyc= +github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.8 h1:GVvpQbXfUVPnpydvOt+CfZPaZgLcGyJoJRSefunMuIo= +github.com/aws/aws-sdk-go-v2/service/keyspaces v1.10.8/go.mod h1:ROjezftKq0KTWdrXyweta/WkqytcwIIB4/8u1f5qM6A= github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4 h1:Oe8awBiS/iitcsRJB5+DHa3iCxoA0KwJJf0JNrYMINY= github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4/go.mod h1:RCZCSFbieSgNG1RKegO26opXV4EXyef/vNBVJsUyHuw= github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2 v1.25.2 h1:U3w0gmiIoXKn3TVR8vQTcLGRlPyAW5mcQGBqdVqUeQo=