Git Product home page Git Product logo

aws-request-signing-apache-interceptor's Introduction

AWS Request Signing Interceptor

tests

An AWS request signing interceptor for arbitrary HTTP requests.

This library enables you to sign requests to any service that leverages SigV4, and thus access any AWS Service or APIG-backed service.

This library is based on AWS Interceptor, but using AWS SDK 2.x.

Usage

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import io.github.acm19.aws.interceptor.http.AwsRequestSigningApacheInterceptor;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.regions.Region;

public static void main(String[] args) throws ClientProtocolException, IOException {
        HttpRequestInterceptor interceptor = new AwsRequestSigningApacheInterceptor(
                "service",
                Aws4Signer.create(), 
                DefaultCredentialsProvider.create(), 
                Region.US_WEST_2
        );

        CloseableHttpClient client = HttpClients.custom()
                .addInterceptorLast(interceptor)
                .build();

        HttpGet httpGet = new HttpGet("https://...");
        CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
        System.out.println(httpResponse.getStatusLine());

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(
                        httpResponse.getEntity().getContent()
                )
        );

        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = reader.readLine()) != null) {
                response.append(inputLine);
        }
        reader.close();

        System.out.println(response.toString());
        httpClient.close();
}

Examples

To run the Amazon OpenSearch Sample, replace the values of host and region in the source and run the following.

export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=

mvn test-compile exec:java -Dexec.classpathScope=test -Dexec.mainClass="io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample"

See examples for more valid requests.

Contributing

You're encouraged to contribute to this project. See CONTRIBUTING for details.

Copyright

Copyright 2017 Amazon.com, Inc. or its affiliates. See NOTICE for details.

License

This library is licensed under the Apache 2.0 License.

aws-request-signing-apache-interceptor's People

Contributors

acm19 avatar aetter avatar cheruvian avatar dblock avatar jpeddicord avatar maronhatoum avatar renovate-bot avatar renovate[bot] avatar

aws-request-signing-apache-interceptor's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository.

  • WARN: Error updating branch: update failure

Errored

These updates encountered an error and will be retried. Click on a checkbox below to force a retry now.

  • Update dependency software.amazon.awssdk:auth to v2.17.226
  • Update dependency org.junit:junit-bom to v5.9.0-RC1
  • Update dependency com.puppycrawl.tools:checkstyle to v10
  • Update dependency org.apache.maven.plugins:maven-site-plugin to v4
  • Update dependency org.apache.maven.plugins:maven-surefire-plugin to v3

Detected dependencies

github-actions
.github/workflows/test.yml
  • actions/checkout v3
  • actions/setup-java v3
  • actions/cache v3
maven
pom.xml
  • org.junit:junit-bom 5.8.2
  • software.amazon.awssdk:auth 2.17.222
  • org.apache.httpcomponents:httpclient 4.5.13
  • org.apache.maven.plugins:maven-surefire-plugin 2.22.2
  • org.codehaus.mojo:versions-maven-plugin 2.11.0
  • org.apache.maven.plugins:maven-source-plugin 3.2.1
  • org.apache.maven.plugins:maven-javadoc-plugin 3.4.0
  • org.apache.maven.plugins:maven-jar-plugin 3.2.2
  • org.apache.maven.plugins:maven-site-plugin 3.12.0
  • org.apache.maven.plugins:maven-project-info-reports-plugin 3.3.0
  • org.apache.maven.plugins:maven-checkstyle-plugin 3.1.2
  • com.puppycrawl.tools:checkstyle 9.3
  • org.apache.maven.plugins:maven-checkstyle-plugin 3.1.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.