private function signRequest(
        RequestInterface $request,
        array $packedCommands = []
    ): RequestInterface {
        $signature = [
            $request->getMethod(),
            $request->getHeaderLine('Content-MD5'),
            $request->getHeaderLine('Content-Type'),
            $request->getHeaderLine('Date')
        ];

        $normalizedCommands = [];
        foreach ($packedCommands as $command => $value) {
            if (!empty($value)) {
                $normalizedCommands[] = strtolower($command) . ':' . $value;
            }
        }

        if (!empty($normalizedCommands)) {
            sort($normalizedCommands);
            $signature[] = join("\n", $normalizedCommands);
        }

        $signature[] = $request->getUri()->getPath();

        return $request->withAddedHeader(
            'Authorization',
            'AWS ' . $this->options['key'] . ':' . base64_encode(hash_hmac(
                'sha1',
                join("\n", $signature),
                $this->options['secret'],
                true
            ))
        );
    }