Skip to content

Commit

Permalink
chore: update getting started docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyentoanit committed Oct 15, 2024
1 parent 7f24f64 commit 6b1a83d
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
- A fully typed TypeScript and Node.js SDK package for Amazon Selling Partner API
- Uses models from [API model's repo](https://github.com/amzn/selling-partner-api-models) to generate classes automatically
- Picks up changes and releases daily when/if models have drifted
- Based on Axios and uses [aws4-axios](https://github.com/jamesmbourne/aws4-axios) interceptor to automatically sign the requests
- Can optionally assume roles via STS, and refresh STS credentials on schedule

## Download & Installation

Expand All @@ -41,58 +39,6 @@ the OAuth flow or by using a self-authorized set of credentials.

### Basic Usage

#### Using Existing AWS Credentials

This method is applicable if you want to assume the
[Selling Partner API role](https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#step-4-create-an-iam-role)
yourself, or you are using a static set of user credentials (not recommended).

```ts
import { SellersApiClient } from '@scaleleap/selling-partner-api-sdk'

const stsClient = new STSClient({
// Static set of credentials that have the permission to assume the role above
credentials: {
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY',
},
})

const { Credentials } = await stsClient.send(
new AssumeRoleCommand({
// This is the role you have set in your Selling Partner API application
RoleArn: 'arn:aws:iam::123456789012:role/your-SP-API-role-name',
RoleSessionName: 'selling-partner-api-axios',
}),
)

const client = new SellersApiClient({
accessToken: 'Atza|...',

// Or use `amazonMarketplaces.CA.sellingPartner.region.endpoint`
// from `@scaleleap/amazon-marketplaces` package
basePath: 'https://sellingpartnerapi-na.amazon.com',

// Or use `amazonMarketplaces.CA.sellingPartner.region.awsRegion`
// from `@scaleleap/amazon-marketplaces` package
region: 'us-east-1',

credentials: {
accessKeyId: Credentials?.AccessKeyId || '',
secretAccessKey: Credentials?.SecretAccessKey || '',
sessionToken: Credentials?.SessionToken || '',
}
})

const marketplaceParticipations = await client.getMarketplaceParticipations()
```

#### Letting `@scaleleap/selling-partner-api-sdk` to Assume the Role

This package uses [aws4-axios](https://github.com/jamesmbourne/aws4-axios) under the hood, which
has the capability to make the STS call and get the credentials for you, and refresh the
temporary AWS credentials session.

```ts
import { SellersApiClient } from '@scaleleap/selling-partner-api-sdk'

Expand All @@ -106,15 +52,6 @@ const client = new SellersApiClient({
// Or use `amazonMarketplaces.CA.sellingPartner.region.awsRegion`
// from `@scaleleap/amazon-marketplaces` package
region: 'us-east-1',

// This is the role you have set in your Selling Partner API application
roleArn: 'arn:aws:iam::123456789012:role/your-SP-API-role-name',

// Static set of credentials that have the permission to assume the role above
credentials: {
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY',
},
})

const marketplaceParticipations = await client.getMarketplaceParticipations()
Expand Down

0 comments on commit 6b1a83d

Please sign in to comment.