Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for golang to ecs example documentation #438

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions v2/ecs_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ You may now open `src/MyEcsConstruct.sln` in Visual Studio\.

------

#### [ Go ]

```
mkdir MyEcsConstruct
cd MyEcsConstruct
cdk init --language go
go get
```

------

Run the app and confirm that it creates an empty stack\.

```
Expand Down Expand Up @@ -159,6 +170,18 @@ using Amazon.CDK.AWS.ECS.Patterns;

------

#### [ Go ]

File: `my_ecs_construct.go`

```
"github.com/aws/aws-cdk-go/awscdk/v2/awsec2"
"github.com/aws/aws-cdk-go/awscdk/v2/awsecs"
"github.com/aws/aws-cdk-go/awscdk/v2/awsecspatterns"
```

------

Replace the comment at the end of the constructor with the following code\.

------
Expand Down Expand Up @@ -280,6 +303,31 @@ Replace the comment at the end of the constructor with the following code\.
);
```

------
#### [ Go ]

```
vpc := awsec2.NewVpc(stack, jsii.String("MyVpc"), &awsec2.VpcProps{
MaxAzs: jsii.Number(3), // Default is all AZs in region
})

cluster := awsecs.NewCluster(stack, jsii.String("EcsCluster"), &awsecs.ClusterProps{
Vpc: vpc,
})

awsecspatterns.NewApplicationLoadBalancedFargateService(stack, jsii.String("MyFargateService"), &awsecspatterns.ApplicationLoadBalancedFargateServiceProps{
Cluster: cluster, // Required
Cpu: jsii.Number(512), // Default is 256
DesiredCount: jsii.Number(6), // Default is 1
TaskImageOptions: &awsecspatterns.ApplicationLoadBalancedTaskImageOptions{
Image: awsecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample"), &awsecs.RepositoryImageProps{}),
},
MemoryLimitMiB: jsii.Number(2048), // Default is 512
PublicLoadBalancer: jsii.Bool(true), // Default is true
})

```

------

Save it and make sure it runs and creates a stack\.
Expand Down