@@ -77,6 +77,17 @@ Create an empty project structure for the |cdk| app.
77
77
78
78
.. tabs ::
79
79
80
+ .. group-tab :: C#
81
+
82
+ Create a new empty, source controlled directory and then create a new
83
+ console application.
84
+
85
+ .. code-block :: sh
86
+
87
+ mkdir HelloCdk
88
+ cd HelloCdk
89
+ dotnet new console
90
+
80
91
.. group-tab :: JavaScript
81
92
82
93
Create an empty source-controlled directory for your project and an
@@ -192,6 +203,14 @@ library includes the basic classes needed to write |cdk| stacks and apps.
192
203
193
204
.. tabs ::
194
205
206
+ .. group-tab :: C#
207
+
208
+ Install the **Amazon.CDK NuGet ** package:
209
+
210
+ .. code-block :: sh
211
+
212
+ dotnet add package Amazon.CDK
213
+
195
214
.. group-tab :: JavaScript
196
215
197
216
Install the **@aws-cdk/cdk ** package:
@@ -232,6 +251,26 @@ class. Create an empty **App**:
232
251
233
252
.. tabs ::
234
253
254
+ .. group-tab :: C#
255
+
256
+ In **Program.cs **
257
+
258
+ .. code-block :: c#
259
+
260
+ using Amazon .CDK ;
261
+
262
+ namespace HelloCdk
263
+ {
264
+ class Program
265
+ {
266
+ static void Main (string [] args )
267
+ {
268
+ var myApp = new App ();
269
+ myApp .Run ();
270
+ }
271
+ }
272
+ }
273
+
235
274
.. group-tab :: JavaScript
236
275
237
276
Create the file **bin/hello-cdk.js **:
@@ -293,6 +332,14 @@ If needed, compile the code:
293
332
294
333
.. tabs ::
295
334
335
+ .. group-tab :: C#
336
+
337
+ Compile the code using your IDE or via the dotnet CLI:
338
+
339
+ .. code-block :: sh
340
+
341
+ dotnet build
342
+
296
343
.. group-tab :: JavaScript
297
344
298
345
No need to compile
@@ -358,6 +405,16 @@ your project directory with the following content:
358
405
359
406
.. tabs ::
360
407
408
+ .. group-tab :: C#
409
+
410
+ Define the :code: `--app ` option in a **cdk.json ** file:
411
+
412
+ .. code-block :: json
413
+
414
+ {
415
+ "app" : " dotnet run --project HelloCdk.csproj"
416
+ }
417
+
361
418
.. group-tab :: JavaScript
362
419
363
420
Define the :code: `--app ` option in **cdk.json ** to execute **hello-cdk.js **
@@ -466,6 +523,44 @@ Define a stack and add it to the app.
466
523
467
524
.. tabs ::
468
525
526
+ .. group-tab :: C#
527
+
528
+ Create **MyStack.cs **:
529
+
530
+ .. code-block :: c#
531
+
532
+ using Amazon .CDK ;
533
+
534
+ namespace HelloCdk
535
+ {
536
+ public class MyStack : Stack
537
+ {
538
+ public MyStack (App parent , string name ) : base (parent , name , null )
539
+ {
540
+ }
541
+ }
542
+ }
543
+
544
+ In **Program.cs **:
545
+
546
+ .. code-block :: c#
547
+ : emphasize - lines : 10
548
+
549
+ using Amazon .CDK ;
550
+
551
+ namespace HelloCdk
552
+ {
553
+ class Program
554
+ {
555
+ static void Main (string [] args )
556
+ {
557
+ var myApp = new App ();
558
+ new MyStack (myApp , " hello-cdk" );
559
+ myApp .Run ();
560
+ }
561
+ }
562
+ }
563
+
469
564
.. group-tab :: JavaScript
470
565
471
566
In **index.js **:
@@ -575,6 +670,12 @@ Compile your program:
575
670
576
671
.. tabs ::
577
672
673
+ .. group-tab :: C#
674
+
675
+ We have configured cdk.json to run "dotnet run", which will
676
+ restore dependencies, build, and run your application.
677
+ Therefore, you just need to run the CDK command.
678
+
578
679
.. group-tab :: JavaScript
579
680
580
681
Nothing to compile.
@@ -622,6 +723,12 @@ Install the **@aws-cdk/aws-s3** package:
622
723
623
724
.. tabs ::
624
725
726
+ .. group-tab :: C#
727
+
728
+ .. code-block :: sh
729
+
730
+ dotnet add package Amazon.CDK.AWS.S3
731
+
625
732
.. group-tab :: JavaScript
626
733
627
734
.. code-block :: sh
@@ -651,6 +758,30 @@ the :py:class:`Bucket <@aws-cdk/aws-s3.Bucket>` class:
651
758
652
759
.. tabs ::
653
760
761
+ .. group-tab :: C#
762
+
763
+ Create **MyStack.cs **:
764
+
765
+ .. code-block :: c#
766
+ : emphasize - lines : 2 ,10 ,11 ,12 ,13
767
+
768
+ using Amazon .CDK ;
769
+ using Amazon .CDK .AWS .S3 ;
770
+
771
+ namespace HelloCdk
772
+ {
773
+ public class MyStack : Stack
774
+ {
775
+ public MyStack (App parent , string name ) : base (parent , name , null )
776
+ {
777
+ new Bucket (this , " MyFirstBucket" , new BucketProps
778
+ {
779
+ Versioned = true
780
+ });
781
+ }
782
+ }
783
+ }
784
+
654
785
.. group-tab :: JavaScript
655
786
656
787
In **index.js **:
@@ -739,6 +870,12 @@ Compile your program:
739
870
740
871
.. tabs ::
741
872
873
+ .. group-tab :: C#
874
+
875
+ We have configured cdk.json to run "dotnet run", which will
876
+ restore dependencies, build, and run your application.
877
+ Therefore, you just need to run the CDK command.
878
+
742
879
.. group-tab :: JavaScript
743
880
744
881
Nothing to compile.
@@ -818,6 +955,17 @@ Configure the bucket to use KMS managed encryption:
818
955
819
956
.. tabs ::
820
957
958
+ .. group-tab :: C#
959
+
960
+ .. code-block :: c#
961
+ : emphasize - lines : 4
962
+
963
+ new Bucket (this , " MyFirstBucket" , new BucketProps
964
+ {
965
+ Versioned = true ,
966
+ Encryption = BucketEncryption .KmsManaged
967
+ });
968
+
821
969
.. group-tab :: JavaScript
822
970
823
971
.. code-block :: js
@@ -852,6 +1000,12 @@ Compile the program:
852
1000
853
1001
.. tabs ::
854
1002
1003
+ .. group-tab :: C#
1004
+
1005
+ We have configured cdk.json to run "dotnet run", which will
1006
+ restore dependencies, build, and run your application.
1007
+ Therefore, you just need to run the CDK command.
1008
+
855
1009
.. group-tab :: JavaScript
856
1010
857
1011
Nothing to compile.
0 commit comments