Repository: dapr/components-contrib (go)

Issue:
aws sqs component can not support  China region such as cn-northwest-1
<!-- If you need to report a security issue please visit https://docs.dapr.io/operations/support/support-security-issues -->

## Expected Behavior

<!-- Briefly describe what you expect to happen -->
### I create  sqs component  and  set correct  sqs config info . 
when  I pub message  by the component  ,I hope it work well ,but the daprd output error message as below.

## Actual Behavior

<!-- Briefly describe what is actually happening -->

![image](https://user-images.githubusercontent.com/38551720/180633118-9f2371f2-8825-4188-9657-2fe646765f82.png)


## Steps to Reproduce the Problem

<!-- How can a maintainer reproduce this issue (be detailed) -->

If I set  cn-northwest-1 to the region,   it will connect error，maybe cn-north-1 also have the same  problem。

I found  the source code   on buildARN  function   in snssqs.go  .  

### return fmt.Sprintf("arn:aws:%s:%s:%s:%s", serviceName, s.metadata.Region, s.metadata.accountID, entityName)

 If region is  cn-*,the arn  should start with   arn:aws-cn 

### return fmt.Sprintf("arn:**aws-cn**:%s:%s:%s:%s", serviceName, s.metadata.Region, s.metadata.accountID, entityName)


![image](https://user-images.githubusercontent.com/38551720/180632668-371a9d7e-74e6-44ef-a241-d54178a68037.png)
snssqs.go 
![image](https://user-images.githubusercontent.com/38551720/180632249-bf9c8f07-760f-418f-8a60-f32a3fe78d94.png)


## Release Note

<!-- How should the fix for this issue be communicated in our release notes? It can be populated later. -->
<!-- Keep it as a single line. Examples: -->

<!-- RELEASE NOTE: **ADD** New feature in Dapr. -->
<!-- RELEASE NOTE: **FIX** Bug in runtime. -->
<!-- RELEASE NOTE: **UPDATE** Runtime dependency. -->

RELEASE NOTE:


Pull request:
pubsub.snssqs: Support regions in other AWS partitions
Fixes #1907

Signed-off-by: Clare Liguori <liguori@amazon.com>

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

* [x] Code compiles correctly
* [x] Created/updated tests
* [ ] Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#_[issue number]_


Patch:
diff --git a/pubsub/aws/snssqs/metadata.go b/pubsub/aws/snssqs/metadata.go
index f77c0161..cbfd7d3a 100644
--- a/pubsub/aws/snssqs/metadata.go
+++ b/pubsub/aws/snssqs/metadata.go
@@ -7,6 +7,8 @@ import (
 
 	mdutils "github.com/dapr/components-contrib/metadata"
 	"github.com/dapr/components-contrib/pubsub"
+
+	"github.com/aws/aws-sdk-go/aws/endpoints"
 )
 
 type snsSqsMetadata struct {
@@ -20,6 +22,8 @@ type snsSqsMetadata struct {
 	SessionToken string
 	// aws region in which SNS/SQS should create resources.
 	Region string
+	// aws partition in which SNS/SQS should create resources.
+	Partition string
 	// name of the queue for this application. The is provided by the runtime as "consumerID".
 	sqsQueueName string
 	// name of the dead letter queue for this application.
@@ -178,6 +182,12 @@ func (md *snsSqsMetadata) setCredsAndQueueNameConfig(metadata pubsub.Metadata) e
 
 	if val, ok := mdutils.GetMetadataProperty(metadata.Properties, "awsRegion", "region"); ok {
 		md.Region = val
+
+		if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), val); ok {
+			md.Partition = partition.ID()
+		} else {
+			md.Partition = "aws"
+		}
 	}
 
 	if val, ok := metadata.Properties["consumerID"]; ok {
diff --git a/pubsub/aws/snssqs/snssqs.go b/pubsub/aws/snssqs/snssqs.go
index e65af603..3808ee3c 100644
--- a/pubsub/aws/snssqs/snssqs.go
+++ b/pubsub/aws/snssqs/snssqs.go
@@ -206,7 +206,7 @@ func (s *snsSqs) setAwsAccountIDIfNotProvided(parentCtx context.Context) error {
 }
 
 func (s *snsSqs) buildARN(serviceName, entityName string) string {
-	return fmt.Sprintf("arn:aws:%s:%s:%s:%s", serviceName, s.metadata.Region, s.metadata.accountID, entityName)
+	return fmt.Sprintf("arn:%s:%s:%s:%s:%s", s.metadata.Partition, serviceName, s.metadata.Region, s.metadata.accountID, entityName)
 }
 
 func (s *snsSqs) createTopic(parentCtx context.Context, topic string) (string, error) {


Test patch:
diff --git a/pubsub/aws/snssqs/snssqs_test.go b/pubsub/aws/snssqs/snssqs_test.go
index 9be21f43..61c61101 100644
--- a/pubsub/aws/snssqs/snssqs_test.go
+++ b/pubsub/aws/snssqs/snssqs_test.go
@@ -400,3 +400,72 @@ func Test_replaceNameToAWSSanitizedExistingFifoName_Trimmed(t *testing.T) {
 	r.Equal(80, len(v))
 	r.Equal("012345678901234567890123456789012345678901234567890123456789012345678901234.fifo", v)
 }
+
+func Test_buildARN_DefaultPartition(t *testing.T) {
+	t.Parallel()
+	r := require.New(t)
+	l := logger.NewLogger("SnsSqs unit test")
+	l.SetOutputLevel(logger.DebugLevel)
+	ps := snsSqs{
+		logger: l,
+	}
+
+	md, err := ps.getSnsSqsMetatdata(pubsub.Metadata{Properties: map[string]string{
+		"consumerID": "c",
+		"accessKey":  "a",
+		"secretKey":  "s",
+		"region":     "r",
+	}})
+	r.NoError(err)
+	md.accountID = "123456789012"
+	ps.metadata = md
+
+	arn := ps.buildARN("sns", "myTopic")
+	r.Equal("arn:aws:sns:r:123456789012:myTopic", arn)
+}
+
+func Test_buildARN_StandardPartition(t *testing.T) {
+	t.Parallel()
+	r := require.New(t)
+	l := logger.NewLogger("SnsSqs unit test")
+	l.SetOutputLevel(logger.DebugLevel)
+	ps := snsSqs{
+		logger: l,
+	}
+
+	md, err := ps.getSnsSqsMetatdata(pubsub.Metadata{Properties: map[string]string{
+		"consumerID": "c",
+		"accessKey":  "a",
+		"secretKey":  "s",
+		"region":     "us-west-2",
+	}})
+	r.NoError(err)
+	md.accountID = "123456789012"
+	ps.metadata = md
+
+	arn := ps.buildARN("sns", "myTopic")
+	r.Equal("arn:aws:sns:us-west-2:123456789012:myTopic", arn)
+}
+
+func Test_buildARN_NonStandardPartition(t *testing.T) {
+	t.Parallel()
+	r := require.New(t)
+	l := logger.NewLogger("SnsSqs unit test")
+	l.SetOutputLevel(logger.DebugLevel)
+	ps := snsSqs{
+		logger: l,
+	}
+
+	md, err := ps.getSnsSqsMetatdata(pubsub.Metadata{Properties: map[string]string{
+		"consumerID": "c",
+		"accessKey":  "a",
+		"secretKey":  "s",
+		"region":     "cn-northwest-1",
+	}})
+	r.NoError(err)
+	md.accountID = "123456789012"
+	ps.metadata = md
+
+	arn := ps.buildARN("sns", "myTopic")
+	r.Equal("arn:aws-cn:sns:cn-northwest-1:123456789012:myTopic", arn)
+}