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

Fatal error when connecting to DynamoDB. #95

Closed
ADGrant opened this issue Dec 30, 2018 · 7 comments
Closed

Fatal error when connecting to DynamoDB. #95

ADGrant opened this issue Dec 30, 2018 · 7 comments

Comments

@ADGrant
Copy link

ADGrant commented Dec 30, 2018

Get Fatal error: Unexpectedly found nil while unwrapping an Optional val

#7 0x00000001018a2f4c in Signers.V4.signedHeaders(url:headers:method:date:bodyData:) at .build/checkouts/aws-sdk-swift-core.git--8673986503349919441/Sources/AWSSDKSwiftCore/Signers/V4.swift:96
#8 0x000000010181e60d in AWSClient.nioRequestWithSignedHeader(:) at .build/checkouts/aws-sdk-swift-core.git--8673986503349919441/Sources/AWSSDKSwiftCore/AWSClient.swift:217
#9 0x000000010181de57 in AWSClient.createNIORequestWithSignedHeader(
:) at .build/checkouts/aws-sdk-swift-core.git--8673986503349919441/Sources/AWSSDKSwiftCore/AWSClient.swift:190
#10 0x0000000101819737 in AWSClient.createNioRequest(:) at .build/checkouts/aws-sdk-swift-core.git--8673986503349919441/Sources/AWSSDKSwiftCore/AWSClient.swift:243
#11 0x000000010181d70f in AWSClient.send<A, B>(operation:path:httpMethod:input:) at .build/checkouts/aws-sdk-swift-core.git--8673986503349919441/Sources/AWSSDKSwiftCore/AWSClient.swift:171
#12 0x0000000101094273 in DynamoDB.getItem(
:) at .build/checkouts/aws-sdk-swift.git--2129101693774578373/Sources/AWSSDKSwift/Services/DynamoDB/DynamoDB_API.swift:91

code in signedHeaders(url: URL, headers: [String: String], method: String, date: Date = Date(), bodyData: Data) -> [String: String]

      var headersForSign = [
            "x-amz-content-sha256": hexEncodedBodyHash(bodyData),
            "x-amz-date": datetime,
            "Host": url.hostWithPort!, // Forced unwrap fatal error is here 
        ]
@jonnymacs
Copy link
Member

@ADGrant can you share your code to initialize DynamoDB? Are you setting the endpoint by any chance?

@ADGrant
Copy link
Author

ADGrant commented Dec 31, 2018

@jonnymacs see the code below. I am setting the end point.

connection = DynamoDB(accessKeyId: "", secretAccessKey: "*", region: .useast1, endpoint: "dynamodb.us-east-1.amazonaws.com")

let userAttr = DynamoDB.AttributeValue(s: user.name)
let query = DynamoDB.GetItemInput(key: ["user" : userAttr], tableName: "people_users")
let result = try connection?.getItem(query);

@jonnymacs
Copy link
Member

jonnymacs commented Dec 31, 2018

@ADGrant ok that's what I suspected. Try initializing without the endpoint. This is an optional parameter that is set automatically based on the service and region.

region is also optional, and you can leave it out. The default is .useast1 so you should be good, but if you need to specify a different region this is ideally set by an env variable AWS_DEFAULT_REGION.

If you must set an endpoint (and this is true for any of the services) it must include the protocol. ex: https://dynamodb.us-east-1.amazonaws.com So this is another option.

Meanwhile, there's an argument that force unwrap here is not a good idea. So I will add a guard around this code in a future release to surface a more helpful error.

@ADGrant
Copy link
Author

ADGrant commented Dec 31, 2018

Thanks, I will try that. I agree that force unwrap is not a good idea here (or in most places, particularly on server side code). One thing that would be helpful would be some simple examples using these APIs.

@ADGrant
Copy link
Author

ADGrant commented Dec 31, 2018

Works now. Thank you for the prompt assistance.

@jonnymacs
Copy link
Member

@ADGrant you're welcome.

And good suggestion on examples. We'll work on this.

PRs are always welcome too 😃

@adam-fowler
Copy link
Member

Closing as I don’t think there is anything to add here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants