Skip to content

Commit 042836d

Browse files
authored
Merge branch 'aws-samples:main' into main
2 parents 89c1d32 + edddcf1 commit 042836d

File tree

124 files changed

+112902
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+112902
-499
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Ensure DocGen metadata is valid for internal AWS docs build
2+
# https://github.com/awsdocs/aws-doc-sdk-examples-tools
3+
name: Validate DocGen Metadata
4+
5+
on:
6+
# Triggers the workflow on push or pull request events but only for the main branch
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
validate:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: checkout repo content
21+
uses: actions/checkout@v3
22+
- name: validate metadata
23+
uses: awsdocs/aws-doc-sdk-examples-tools@main

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scala/datastax-v4/aws-glue/dist/
2+
**/*.DS_Store

dotnet/datastax-v3/connection-lambda/src/keyspaces-lambda-csharp/keyspaces-lambda-csharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
1313
<PackageReference Include="CassandraCSharpDriver" Version="3.16.2" />
1414
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="1.2.0" />
15-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
15+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
1616
</ItemGroup>
1717
<ItemGroup>
1818
<ResolvedFileToPublish Include="../../AmazonRootCA1.pem">

golang/gocql/connection-sigv4/main.go

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
// snippet-start:[keyspaces.GO.connection.sigv4]
12
package main
23

34
import (
45
"fmt"
56
"log"
7+
"math"
8+
"math/rand"
69
"os"
10+
"time"
711

812
"github.com/aws/aws-sdk-go/aws/session"
913
"github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin/sigv4"
@@ -35,24 +39,37 @@ func init() {
3539
func main() {
3640

3741
//Determine Contact Point
38-
contactPoint := fmt.Sprintf("cassandra.%s.amazonaws.com:9142", awsRegion)
42+
contactPoint := fmt.Sprintf("cassandra.%s.amazonaws.com", awsRegion)
3943
fmt.Println("Using Contact Point ", contactPoint)
4044

4145
// Configure Cluster
4246
cluster := gocql.NewCluster(contactPoint)
4347

48+
cluster.Port = 9142
49+
50+
cluster.NumConns = 4
51+
4452
awsAuth := sigv4.NewAwsAuthenticator()
4553
cluster.Authenticator = awsAuth
4654

55+
//Retry Policy
56+
amazonKeyspacesRetry := &AmazonKeyspacesExponentialBackoffRetryPolicy{Max: 100 * time.Millisecond , Min: 10 * time.Millisecond, NumRetries: 20}
57+
cluster.RetryPolicy = amazonKeyspacesRetry
58+
59+
amazonKeyspacesConnectionObserver, _ := NewAmazonKeyspacesObserver()
60+
cluster.ConnectObserver = amazonKeyspacesConnectionObserver
61+
4762
// Configure Connection TrustStore for TLS
4863
cluster.SslOpts = &gocql.SslOptions{
4964
CaPath: "certs/sf-class2-root.crt",
65+
EnableHostVerification: false,
5066
}
5167

5268
cluster.Consistency = gocql.LocalQuorum
53-
cluster.DisableInitialHostLookup = true
69+
cluster.DisableInitialHostLookup = false
5470

5571
cassandraSession, err := cluster.CreateSession()
72+
5673
if err != nil {
5774
fmt.Println("Cassandra Session Creation Error - ", err)
5875
os.Exit(-2)
@@ -62,7 +79,10 @@ func main() {
6279

6380
// Perform Query
6481
var keyspaceName string
65-
iter := cassandraSession.Query("SELECT keyspace_name FROM system_schema.keyspaces;").Iter()
82+
query := cassandraSession.Query("SELECT keyspace_name FROM system_schema.keyspaces;")
83+
query.Idempotent(true)
84+
iter := query.Iter()
85+
6686
defer iter.Close()
6787

6888
for iter.Scan(&keyspaceName) {
@@ -72,3 +92,60 @@ func main() {
7292
log.Fatal(err)
7393
}
7494
}
95+
//Observer for debugging connection
96+
func NewAmazonKeyspacesObserver() (*AmazonKeyspacesObserver, error) {
97+
s := &AmazonKeyspacesObserver{
98+
}
99+
return s, nil
100+
}
101+
102+
type AmazonKeyspacesObserver struct {}
103+
104+
func (e *AmazonKeyspacesObserver) ObserveConnect(q gocql.ObservedConnect) {
105+
106+
if q.Err != nil {
107+
fmt.Printf("Error Connecting to IP:%s, Port:%d Error: %s\n", q.Host.ConnectAddress(), q.Host.Port(), q.Err)
108+
} else {
109+
fmt.Printf("Connected to hostid:%s, IP:%s, Port:%d, elapse:%d\n", q.Host.HostID(), q.Host.ConnectAddress(), q.Host.Port(), q.End.UnixMilli()-q.Start.UnixMilli())
110+
}
111+
}
112+
113+
114+
//AmazonKeyspacesExponentialBackoffRetryPolicy will retry exponentially on the same connection
115+
type AmazonKeyspacesExponentialBackoffRetryPolicy struct {
116+
NumRetries int
117+
Min, Max time.Duration
118+
}
119+
120+
func (e *AmazonKeyspacesExponentialBackoffRetryPolicy) Attempt(q gocql.RetryableQuery) bool {
121+
if q.Attempts() > e.NumRetries {
122+
return false
123+
}
124+
time.Sleep(e.napTime(q.Attempts()))
125+
return true
126+
}
127+
// used to calculate exponentially growing time
128+
func getExponentialTime(min time.Duration, max time.Duration, attempts int) time.Duration {
129+
if min <= 0 {
130+
min = 100 * time.Millisecond
131+
}
132+
if max <= 0 {
133+
max = 10 * time.Second
134+
}
135+
minFloat := float64(min)
136+
napDuration := minFloat * math.Pow(2, float64(attempts-1))
137+
// add some jitter
138+
napDuration += rand.Float64()*minFloat - (minFloat / 2)
139+
if napDuration > float64(max) {
140+
return time.Duration(max)
141+
}
142+
return time.Duration(napDuration)
143+
}
144+
// GetRetryType will always retry instead of RetryNextHost
145+
func (e *AmazonKeyspacesExponentialBackoffRetryPolicy) GetRetryType(err error) gocql.RetryType {
146+
return gocql.Retry
147+
}
148+
func (e *AmazonKeyspacesExponentialBackoffRetryPolicy) napTime(attempts int) time.Duration {
149+
return getExponentialTime(e.Min, e.Max, attempts)
150+
}
151+
// snippet-end:[keyspaces.GO.connection.sigv4]

java/datastax-v4/connection-lambda/src/main/resources/application.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ datastax-java-driver {
66
}
77
basic.load-balancing-policy {
88
local-datacenter = "us-west-2"
9+
slow-replica-avoidance = false
910
}
1011
advanced {
12+
reconnect-on-init = true
1113
auth-provider = {
1214
class = software.aws.mcs.auth.SigV4AuthProvider
1315
aws-region = "us-west-2"

java/datastax-v4/connection-sigv4/src/main/resources/application-full.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ datastax-java-driver {
22
basic.contact-points = [ "cassandra.us-east-2.amazonaws.com:9142" ]
33
basic.load-balancing-policy {
44
class = DefaultLoadBalancingPolicy
5+
slow-replica-avoidance = false
56
}
67
advanced {
8+
reconnect-on-init = true
79
auth-provider = {
810
class = software.aws.mcs.auth.SigV4AuthProvider
911
aws-region = us-east-2
@@ -12,5 +14,6 @@ datastax-java-driver {
1214
class = DefaultSslEngineFactory
1315
hostname-validation = false
1416
}
17+
connection.pool.local.size = 3
1518
}
1619
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
datastax-java-driver {
22
basic.load-balancing-policy {
33
class = DefaultLoadBalancingPolicy
4+
slow-replica-avoidance = false
45
}
56
advanced {
7+
reconnect-on-init = true
68
auth-provider = {
79
class = software.aws.mcs.auth.SigV4AuthProvider
810
}
911
ssl-engine-factory {
1012
class = DefaultSslEngineFactory
1113
hostname-validation = false
1214
}
15+
connection.pool.local.size = 3
1316
}
1417
}

java/datastax-v4/connection-vpc-endpoint/src/main/resources/application-full.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ datastax-java-driver {
33
contact-points = [ "cassandra.us-east-2.amazonaws.com:9142" ]
44
load-balancing-policy {
55
class = DefaultLoadBalancingPolicy
6+
slow-replica-avoidance = false
67
}
78
request {
89
default-idempotence = true
910
}
1011
}
1112
advanced {
13+
reconnect-on-init = true
1214
auth-provider = {
1315
class = software.aws.mcs.auth.SigV4AuthProvider
1416
aws-region = us-east-2

java/datastax-v4/connection-vpc-endpoint/src/main/resources/application.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ datastax-java-driver {
22
basic {
33
load-balancing-policy {
44
class = DefaultLoadBalancingPolicy
5+
slow-replica-avoidance = false
56
}
67
request {
78
default-idempotence = true
89
}
910
}
1011

1112
advanced {
13+
reconnect-on-init = true
14+
1215
auth-provider = {
1316
class = software.aws.mcs.auth.SigV4AuthProvider
1417
}

java/datastax-v4/eks/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)