Skip to content

Commit 1201a5c

Browse files
authored
.NET v4: Redshift Basics Scenario (#7661)
1 parent 419a5da commit 1201a5c

File tree

17 files changed

+2476
-352
lines changed

17 files changed

+2476
-352
lines changed

.doc_gen/metadata/redshift_metadata.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ redshift_Hello:
55
synopsis: get started using &RS;.
66
category: Hello
77
languages:
8+
.NET:
9+
versions:
10+
- sdk_version: 4
11+
github: dotnetv4/Redshift
12+
excerpts:
13+
- description:
14+
snippet_tags:
15+
- Redshift.dotnetv4.Hello
816
Go:
917
versions:
1018
- sdk_version: 2
@@ -35,6 +43,14 @@ redshift_Hello:
3543
redshift: {DescribeClusters}
3644
redshift_ListDatabases:
3745
languages:
46+
.NET:
47+
versions:
48+
- sdk_version: 4
49+
github: dotnetv4/Redshift
50+
excerpts:
51+
- description:
52+
snippet_tags:
53+
- Redshift.dotnetv4.ListDatabases
3854
Java:
3955
versions:
4056
- sdk_version: 2
@@ -48,6 +64,14 @@ redshift_ListDatabases:
4864
redshift: {ListDatabases}
4965
redshift_CreateCluster:
5066
languages:
67+
.NET:
68+
versions:
69+
- sdk_version: 4
70+
github: dotnetv4/Redshift
71+
excerpts:
72+
- description:
73+
snippet_tags:
74+
- Redshift.dotnetv4.CreateCluster
5175
Go:
5276
versions:
5377
- sdk_version: 2
@@ -105,6 +129,14 @@ redshift_CreateCluster:
105129
redshift: {CreateCluster}
106130
redshift_DeleteCluster:
107131
languages:
132+
.NET:
133+
versions:
134+
- sdk_version: 4
135+
github: dotnetv4/Redshift
136+
excerpts:
137+
- description:
138+
snippet_tags:
139+
- Redshift.dotnetv4.DeleteCluster
108140
Go:
109141
versions:
110142
- sdk_version: 2
@@ -162,6 +194,14 @@ redshift_DeleteCluster:
162194
redshift: {DeleteCluster}
163195
redshift_DescribeClusters:
164196
languages:
197+
.NET:
198+
versions:
199+
- sdk_version: 4
200+
github: dotnetv4/Redshift
201+
excerpts:
202+
- description:
203+
snippet_tags:
204+
- Redshift.dotnetv4.DescribeClusters
165205
Go:
166206
versions:
167207
- sdk_version: 2
@@ -219,6 +259,14 @@ redshift_DescribeClusters:
219259
redshift: {DescribeClusters}
220260
redshift_ModifyCluster:
221261
languages:
262+
.NET:
263+
versions:
264+
- sdk_version: 4
265+
github: dotnetv4/Redshift
266+
excerpts:
267+
- description:
268+
snippet_tags:
269+
- Redshift.dotnetv4.ModifyCluster
222270
Go:
223271
versions:
224272
- sdk_version: 2
@@ -276,6 +324,14 @@ redshift_ModifyCluster:
276324
redshift: {ModifyCluster}
277325
redshift_DescribeStatement:
278326
languages:
327+
.NET:
328+
versions:
329+
- sdk_version: 4
330+
github: dotnetv4/Redshift
331+
excerpts:
332+
- description:
333+
snippet_tags:
334+
- Redshift.dotnetv4.DescribeStatement
279335
Java:
280336
versions:
281337
- sdk_version: 2
@@ -302,6 +358,14 @@ redshift_DescribeStatement:
302358
redshift: {DescribeStatement}
303359
redshift_GetStatementResult:
304360
languages:
361+
.NET:
362+
versions:
363+
- sdk_version: 4
364+
github: dotnetv4/Redshift
365+
excerpts:
366+
- description:
367+
snippet_tags:
368+
- Redshift.dotnetv4.GetStatementResult
305369
Java:
306370
versions:
307371
- sdk_version: 2
@@ -356,6 +420,17 @@ redshift_Scenario:
356420
- Delete the Amazon Redshift cluster.
357421
category: Basics
358422
languages:
423+
.NET:
424+
versions:
425+
- sdk_version: 4
426+
github: dotnetv4/Redshift
427+
excerpts:
428+
- description: Create a Redshift wrapper class to manage operations.
429+
snippet_tags:
430+
- Redshift.dotnetv4.RedshiftWrapper
431+
- description: Run an interactive scenario demonstrating Redshift basics.
432+
snippet_tags:
433+
- Redshift.dotnetv4.RedshiftScenario
359434
Go:
360435
versions:
361436
- sdk_version: 2

dotnetv4/DotNetV4Examples.sln

Lines changed: 435 additions & 6 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Amazon.Redshift;
8+
using Amazon.Redshift.Model;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace RedshiftActions;
12+
13+
/// <summary>
14+
/// Hello Amazon Redshift example.
15+
/// </summary>
16+
public class HelloRedshift
17+
{
18+
private static ILogger logger = null!;
19+
20+
// snippet-start:[Redshift.dotnetv4.Hello]
21+
/// <summary>
22+
/// Main method to run the Hello Amazon Redshift example.
23+
/// </summary>
24+
/// <param name="args">Command line arguments (not used).</param>
25+
public static async Task Main(string[] args)
26+
{
27+
var redshiftClient = new AmazonRedshiftClient();
28+
29+
Console.WriteLine("Hello, Amazon Redshift! Let's list available clusters:");
30+
31+
var clusters = new List<Cluster>();
32+
33+
try
34+
{
35+
// Use pagination to retrieve all clusters.
36+
var clustersPaginator = redshiftClient.Paginators.DescribeClusters(new DescribeClustersRequest());
37+
38+
await foreach (var response in clustersPaginator.Responses)
39+
{
40+
if (response.Clusters != null)
41+
clusters.AddRange(response.Clusters);
42+
}
43+
44+
Console.WriteLine($"{clusters.Count} cluster(s) retrieved.");
45+
46+
foreach (var cluster in clusters)
47+
{
48+
Console.WriteLine($"\t{cluster.ClusterIdentifier} (Status: {cluster.ClusterStatus})");
49+
}
50+
}
51+
catch (AmazonRedshiftException ex)
52+
{
53+
Console.WriteLine($"Couldn't list clusters. Here's why: {ex.Message}");
54+
}
55+
catch (Exception ex)
56+
{
57+
Console.WriteLine($"An error occurred: {ex.Message}");
58+
}
59+
}
60+
// snippet-end:[Redshift.dotnetv4.Hello]
61+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>latest</LangVersion>
8+
<AssemblyName>RedshiftActions</AssemblyName>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.3.13" />
13+
<PackageReference Include="AWSSDK.Redshift" Version="4.0.4.1" />
14+
<PackageReference Include="AWSSDK.RedshiftDataAPIService" Version="4.0.3" />
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Content Include="settings.*.json">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
<DependentUpon>settings.json</DependentUpon>
26+
</Content>
27+
</ItemGroup>
28+
</Project>

0 commit comments

Comments
 (0)