Discuss you're experiences and questions with the Developer Preview AWS SDK for Go v2
skmcgrail on updateDocs
skmcgrail on documentation
Regenerated Documentation (#139… (compare)
skmcgrail on updateModels
skmcgrail on main
Update API Models for Release (… (compare)
../../../../pkg/mod/github.com/aws/aws-sdk-go-v2/service/sts@v0.29.0/api_op_AssumeRole.go:326:2: undefined: "github.com/aws/aws-sdk-go-v2/aws/middleware".AddRequestInvocationIDMiddleware
$ make smithy-generate
cd codegen && ./gradlew clean build -Plog-tests && ./gradlew clean
/Users/milosgajdos/go/src/github.com/aws/aws-sdk-go-v2/codegen
> Configure project :protocol-test-codegen
(scanned and found a Smithy CLI version 1.5.1. You will need to add an explicit dependency on smithy-model if publishing a JAR)
> Configure project :sdk-codegen
(scanned and found a Smithy CLI version 1.5.1. You will need to add an explicit dependency on smithy-model if publishing a JAR)
> Task :smithy-aws-go-codegen:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':smithy-aws-go-codegen:compileJava'.
> Could not resolve all files for configuration ':smithy-aws-go-codegen:compileClasspath'.
> Could not find software.amazon.smithy:smithy-go-codegen:0.1.0.
Searched in the following locations:
- file:/Users/milosgajdos/.m2/repository/software/amazon/smithy/smithy-go-codegen/0.1.0/smithy-go-codegen-0.1.0.pom
- https://repo.maven.apache.org/maven2/software/amazon/smithy/smithy-go-codegen/0.1.0/smithy-go-codegen-0.1.0.pom
Required by:
project :smithy-aws-go-codegen
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
4 actionable tasks: 1 executed, 3 up-to-date
make: *** [smithy-generate] Error 1
Hey all! I've been trying to do the following against Route53 with the v2 SDK ...
Creating the Hosted Zone for the subdomain is no problem but adding the NS record fails with the following error message:InvalidInput: Invalid request: Expected exactly one of [Weight, Region, Failover, GeoLocation, or MultiValueAnswer], but found none in Change with [Action=UPSERT, Name=subdomain1.apps.example.com., Type=NS, SetIdentifier=Upsert NS record]
If I use the AWS Management Console to add the NS record, I do not need to specify any of the above and it works great. What is the proper way of adding an NS record to a Hosted Zone? Can't find any examples out there for NS records.
Here's the code snippet I'm working with:
params := route53.ChangeResourceRecordSetsInput{
ChangeBatch: &types.ChangeBatch{
Changes: []types.Change{
{
Action: types.ChangeActionUpsert,
ResourceRecordSet: &types.ResourceRecordSet{
Name: "subdomain1.app.example.com",
Type: types.RRTypeNs,
ResourceRecords: []types.ResourceRecord{
... values goes here ...
},
TTL: aws.Int64(300),
SetIdentifier: aws.String("Upsert NS record"),
},
},
},
Comment: aws.String("Upserting NS record in parent zone"),
},
HostedZoneId: aws.String("<id of parent zone app.example.com>"),
}
res, err := r.Route53.ChangeResourceRecordSets(ctx, ¶ms)
Any help would be much appreciated!
Hello,
I have a service written by using go sdk 1.X and planning to convert it to go-sdk 2, the service has a test that uses the 1.x interfaces for example "github.com/aws/aws-sdk-go/service/ec2/ec2iface
and instantiate objects to mock the service in the test.
My question is
hello everyone, I am trying to disable sourcedestcheck on the ENI level, this block of code works if SourceDestCheck: is true, but says api error InvalidParameterCombination: No attributes specified.
if SourceDestCheck: is false, I am stuck on how to disable SourceDestCheck
``` input := &ec2.ModifyNetworkInterfaceAttributeInput{
NetworkInterfaceId: aws.String(eni),
SourceDestCheck: &types.AttributeBooleanValue{
Value: false,
},
}
_, err := client.ModifyNetworkInterfaceAttribute(context.Background(), input)
```
package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/lambda"
)
var client dynamodb.Client
func init() {
// Using the SDK's default configuration, loading additional config
// and credentials values from the environment variables, shared
// credentials, and shared configuration files
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("eu-central-1"))
if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}
// Using the Config value, create the DynamoDB client
client := dynamodb.NewFromConfig(cfg)
}
func TablesOperation() {
// Build the request with its input parameters
resp, err := client.ListTables(context.TODO(), &dynamodb.ListTablesInput{
Limit: aws.Int32(5),
})
if err != nil {
log.Fatalf("failed to list tables, %v", err)
}
fmt.Println("Tables:")
for _, tableName := range resp.TableNames {
fmt.Println(tableName)
}
}
func main() {
// xray.AWS(dbSession.Client)
lambda.CreateFunctionInput(Handler * TablesOperation)
}
@kbhagi
aws has a lib called go-api-proxy
that you can use to wrap a lambda to respond to a normal http interface
below is an example with gorilla mux
package main
import (
"context"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"github.com/awslabs/aws-lambda-go-api-proxy/gorillamux"
"github.com/gorilla/mux"
)
var adaptor *gorillamux.GorillaMuxAdapter
func init() {
r := mux.NewRouter()
r.HandleFunc("/", YOURHANDLER).Methods("POST")
adaptor = gorillamux.New(r)
}
func main() {
lambda.Start(func(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return adaptor.ProxyWithContext(ctx, req)
})
}
v2
and I have some tests which are now failing: these tests spin up a localstack
instance, create a Kinesis stream, and then put some records into it. They work fine locally but fail in my pipeline, where I'm using a remote DOCKER_HOST
. This is how I have configured it so far. I'm making sure to replace the endpoint
and region
according to my configuration (as much as I could find on the documentation, at least) but CreateStream
fails with context deadline exceeded
. Has anyone encountered similar issues?import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
"github.com/aws/smithy-go"
)
var (
kinesisStreamName = aws.String("my-stream")
kinesisRegion = "eu-west-1"
kinesisShardsCount int32 = 1
)
func TestIt(t *testing.T) {
endpointResolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
if service == kin.ServiceID && region == kinesisRegion {
return aws.Endpoint{
PartitionID: "aws",
URL: kinesisEndpoint,
SigningRegion: kinesisRegion,
}, nil
}
return aws.Endpoint{}, fmt.Errorf("unknown endpoint requested")
})
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(kinesisRegion), config.WithEndpointResolver(endpointResolver))
if err != nil {
logAwsError(s.t, "unable to load AWS configuration", err)
}
client := kinesis.NewFromConfig(cfg)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
_, err := s.testKinesisClient.CreateStream(ctx, &kin.CreateStreamInput{
StreamName: kinesisStreamName,
ShardCount: &kinesisShardsCount,
})
if err != nil {
logAwsError(s.t, "unable to create Kinesis stream", err)
}
}
awslocal
won't return the table either. Manually creating the tables with awslocal
works, and I can list and describe the tables, but then with the v2 sdk describes still return ResourceNotExists
... Feels like the v2 sdk is borked since all other aws provided tooling works fine, but maybe v2 is just using calls that are too fancy for localstack right now... I've yet to properly try against real aws since I'm struggling to get the service passing even basic local testing.
package main
import (
"context"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
awsv1 "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elbv2"
)
type ELBV2DescribeTargetGroupsAPI interface {
DescribeTargetGroups(ctx context.Context,
params *elasticloadbalancingv2.DescribeTargetGroupsInput,
optFns ...func(*elasticloadbalancingv2.Options)) (*elasticloadbalancingv2.DescribeTargetGroupsOutput, error)
}
func GetTargetGroups(c context.Context, api ELBV2DescribeTargetGroupsAPI, input *elasticloadbalancingv2.DescribeTargetGroupsInput) (*elasticloadbalancingv2.DescribeTargetGroupsOutput, error) {
return api.DescribeTargetGroups(c, input)
}
func main() {
// V2
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithSharedConfigProfile("sbx"),
// config.WithClientLogMode(aws.LogRetries|aws.LogRequest),
)
if err != nil {
log.Fatal(err)
}
svc := elasticloadbalancingv2.NewFromConfig(cfg)
input := &elasticloadbalancingv2.DescribeTargetGroupsInput{
TargetGroupArns: []string{
"arn:aws:elasticloadbalancing:us-east-1:XXXXXXXXXXXX:targetgroup/a0e3ff30-08e4a17b024aed88309/2d2200b37e80bc25",
},
}
result, err := GetTargetGroups(context.TODO(), svc, input)
if err != nil {
log.Fatal(err)
}
fmt.Println(result)
// V1
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
Profile: "sbx",
}))
svcv1 := elbv2.New(sess)
inputv1 := &elbv2.DescribeTargetGroupsInput{
TargetGroupArns: []*string{
awsv1.String("arn:aws:elasticloadbalancing:us-east-1:XXXXXXXXXXXXX:targetgroup/a0e3ff30-08e4a17b024aed88309/2d2200b37e80bc25"),
},
}
resultv1, err := svcv1.DescribeTargetGroups(inputv1)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case elbv2.ErrCodeLoadBalancerNotFoundException:
fmt.Println(elbv2.ErrCodeLoadBalancerNotFoundException, aerr.Error())
case elbv2.ErrCodeTargetGroupNotFoundException:
fmt.Println(elbv2.ErrCodeTargetGroupNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
fmt.Println(resultv1)
}
keyCond := expression.KeyAnd(
expression.Key("pk").Equal(expression.Value("pk_val")),
expression.Key("sk").Equal(expression.Value("sk_val")),
)
proj := expression.NamesList(expression.Name("pk"), expression.Name("sk"))
builder := expression.NewBuilder().WithKeyCondition(keyCond).WithProjection(proj)
expr, err := builder.Build()
input := &dynamodb.GetItemInput{
Key: expr.Values(),
TableName: aws.String("table_name"),
}
result, err := client.GetItem(ctx, input)
s3/manager
.GetBucketRegion
function... the documentation says that it will do a non-signed request with anonymous credentials to find the right bucket. However, I'm using a custom endpoint and it's failing with a 403 response. I can make it work by passing some options to override the credentials but since that's not documented I was wondering if I'm abusing the implementation somehow, or if there is a better way to do this.