sony / appsync-client-go Goto Github PK
View Code? Open in Web Editor NEWAWS AppSync golang client library
License: MIT License
AWS AppSync golang client library
License: MIT License
Hi guys,
Is it possible to use API key, Cognito credentials or Lambda auth instead using credentials for all query, mutations, sub and pub?
Cheers,
-mo
Currently implementation of appsync.Client doesn't allow setting a custom header for the requests.
This can be implemented by adding WithHTTPHeader option, for example.
The important use case can be for adding secret additional headers.
There's WithIAMAuthorization, and only the signer from AWS SDK v1 is supported.
Please add the support for SDK v2 v4 signer: https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws/signer/v4#pkg-overview
Thanks!
Hello,
I am trying to switch from API to IAMv2 authentication. The API is working but when I try to use the WithIAMV2 function I get the 1006 error:
2024/01/08 18:47:01 invalid message received: connection_error
2024/01/08 18:47:02 websocket: close 1006 (abnormal closure): unexpected EOF
2024/01/08 18:47:02 connection failed
2024/01/08 18:47:05 ERROR unable to initiate Subscription error="connection failed"
2024/01/08 18:47:08 ERROR unable to create subscription websocket error="connection failed"
I tried a few different approaches and I am still getting this error:
func createSubscriberWithV2(graphEndpoint string, realtimeEndpoint string, rUpdate chan []Radio, connLost chan bool) (*appsync.PureWebSocketSubscriber, error) {
subRequest, err := authorRadioUpdatesSubscriptionPostRequest()
if err != nil {
slog.Error("unable to produce subscription request", "error", err)
return nil, err
}
ctx := context.TODO()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
return nil, err
}
credentials, err := cfg.Credentials.Retrieve(ctx)
if err != nil {
log.Fatalln(err)
return nil, err
}
signer := sdkv2v4.NewSigner()
opt := appsync.WithIAMV2(signer, credentials, cfg.Region, graphEndpoint)
// opt := appsync.WithIAMV2(signer, credentials, cfg.Region, graphEndpoint)
ws := appsync.NewPureWebSocketSubscriber(
realtimeEndpoint,
subRequest,
// Anonymous function that handles subscription events
func(r *graphql.Response) {
radios := new([]Radio)
slog.Info("received radio subscription update")
if err = r.DataAs(radios); err != nil {
slog.Error("unable to process radio update from subscription", "error", err)
} else {
rUpdate <- *radios
}
},
// Anonymous function that handles subscription lost event
func(err error) {
slog.Error("subscription lost", "error", err)
connLost <- true
},
opt,
)
//this error may be related to this: https://github.com/sony/appsync-client-go/pull/11/commits/9670282ce3a1f51a1d2be738737f4445dfcf2948
err = ws.Start()
if err != nil {
slog.Error("unable to initiate Subscription", "error", err)
return nil, err
}
return ws, nil
}
I have ensured the credentials are correct, along with the http and real-time endpoint. Do you have any suggestions I could try?
Hello.
I'm willing to use your package to make query requests to appsync. Is there a way to configure appsync credentials? Do you have any example of this?
I'm trying to make a request in one of my lambda's which has IAM permission to access my graphql api. I don't see how to do it in the examples.
Hi,
I am using Appsync with API key authorization. Does this library allow for it?
Previously the code, is checking for an error string containing "i/o timeout" to handle connection loss. However, the error message "read: operation timed out" does not match the check.
To address this, I modified the error checking to cover more cases. Instead of looking for a specific error string, check for a timeout is using the net.Error interface and its Timeout() method. This approach is generally more reliable and less prone to breakage if the error messages change.
Before:
_, payload, err := r.ws.ReadMessage()
if err != nil {
log.Println(err)
if strings.Contains(err.Error(), "i/o timeout") {
r.onConnectionLost(err)
}
return
}
After
_, payload, err := r.ws.ReadMessage()
if err != nil {
log.Println(err)
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
r.onConnectionLost(err)
}
return
}
Right now the service being signed is hardcoded to "appsync". However for custom gql domains, these look like API Gateway, and the service for this needs to be "execute-api"
Regarding line 55 in client.go
Hi - is this still maintained?
When I try to run the appsync_eventapp.go against the sample Event App I get the following error:
appsync_eventapp.go:68: subscription subscribeToEventComments()
go/src/github.com/sony/appsync-client-go/pure_websocket_subscriber.go:256: invalid message received
go/src/github.com/sony/appsync-client-go/pure_websocket_subscriber.go:241: websocket: close 1006 (abnormal closure): unexpected EOF
go/src/awesomeProject/demo.go:115: connection failed
The mutations do work. Any idea why this could happen?
Hey,
First, thanks for this library it has been a massive help.
I am looking to run a Linux service and receive notifications from an appsync service. After a day or two, it looks like we are losing the subscription connection and it is silently failing.
Is this something that maybe cause by a timeout? Do we need to do some sort of subscription 'keep-alive'?
Kind Regards
Hello,
I am wondering if there is interest in adding an slog logger to the code base. https://go.dev/blog/slog
PROS: slog is a structured logging library that enhances logging capabilities in projects. It enables projects that import the module to configure log levels according to their needs. This feature allows for more precise control over what is logged, ensuring that developers can focus on the most relevant log information.
CONS: The library was added to the standard library in 1.21. Go version 1.21 would be required to support this library.
If this is something you think would be beneficial I would be happy to start writing it.
Kind regards,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.