Configure the Event Consumer SDK for Buy with Prime
Buy with Prime API is now available for early access
Sign up for early access to the Buy with Prime API using the 'Sign Up' button below. The API may change as Amazon receives feedback and iterates on it.
The event consumer SDK for Buy with Prime helps the Salesforce OMS receive updates from the backend related to order fulfillment.
Prerequisites
Before configuring the event consumer SDK, do the following.
Create a connected app for Buy with Prime
In your Salesforce organization, create a Salesforce connected app for Buy with Prime. For details, see Create Your Salesforce Connected App for Buy with Prime.
Log in to the AWS Management Console
In a browser, log in to the Amazon Web Services (AWS) Management Console and keep the console open for next steps.
Install NPM
Install Node.js version 14.19 or later. For details about downloading and installing Node.js, see the Node.js website.
The codebase for the event consumer SDK uses TypeScript, compiled using tools managed by Node Package Manager (NPM).
Install the AWS CDK CLI tool
To prepare for deploying the event consumer SDK to your AWS instance, install the AWS Cloud Development Kit (CDK) CLI tool. For details about installing the AWS CDK CLI, see What is the AWS CDK?
Authenticate to the AWS CDK CLI
Generate tokens for the AWS Identity and Access Management (IAM) user that is to deploy the event consumer SDK, and use the tokens for authentication to the AWS CDK CLI. For details, see Authenticating using IAM user credentials for the AWS CLI.
Upload credentials for the Salesforce OMS to AWS Secrets Manager
To upload credentials for the Salesforce OMS to AWS Secrets Manager, do the following:
- In your Salesforce organization, retrieve your consumer key, consumer secret, and the domain URL. For details, see Create Your Salesforce Connected App for Buy with Prime.
- In the AWS Management Console, navigate to AWS Secrets Manager, and then choose Store a new Secret.
- For Secret Type, choose Other type of secret.
- Add the following key-value pairs:
- Enter a
consumerKey
key with a value equal to your consumer key. - Enter a
consumerSecret
key with a value equal to your consumer secret. - Enter a
destinationUrl
key with a value equal to the domain URL for your Salesforce organization.
- Enter a
- (Optional) To manage the encryption yourself, choose an encryption key, otherwise leave the default encryption key.
- Choose Next, and then for Secret Name enter
SFOMSDestinationCredentials-{stageName}
, where{stageName}
is the name of the deployment stage, for exampleSFOMSDestinationCredentials-dev
orSFOMSDestinationCredentials-prod
. If you want, add a description and tags. - Choose Next, and then skip the Configure Rotation step by choosing Next.
- Choose Store.
Clone the event consumer SDK
The event consumer SDK for Buy with Prime is available from a repository on GitHub.
- To get access to the repository, reach out to your Buy with Prime solutions architect.
- After you have access, open the following repository:
https://github.com/Buy-with-Prime/buy-with-prime-event-hydrator
- Clone the repository.
Update the destination configuration
To update the destination for the event consumer SDK to the Salesforce OMS, do the following:
- Open the AWS Management Console.
- Navigate to AWS Secrets Manager.
- Open the secret that you created, and then copy the Secret ARN.
- In your
buy-with-prime-event-hydrator
repository, in theconfiguration
directory, open thedestination_config.ts
file. - Replace
<SF_OMS_DESTINATION_API_SECRETS_ARN>
with the ARN. - Save the
destination_config.ts
file.
Update the source configuration
To update the source configuration for the event consumer SDK, do the following:
- In the AWS Management Console, navigate to Amazon EventBridge, and then choose the Event Buses tab.
- In the Custom event bus table, find the row for your Buy with Prime event bus, for example a name starting with aws.partner/buywithprime/.
- Copy the ARN for the event bus.
- In your
buy-with-prime-event-hydrator
repository, in theconfiguration
directory, open thesource_config.ts
file. - In the
sampleSourceConfig
variable, for theBWP_EVENT_BUS_ARN
property, replace the string with the ARN for the event bus. - Navigate to AWS Secrets Manager, and then choose the Secrets tab.
- Open the secret that contains your Buy with Prime client credentials, and then copy the Secret ARN.
- In the
source_config.ts
file, for theBWP_API_SECRETS_ARN
property, replace<BWP_API Secrets_ARN>
with the ARN for your client credentials. - Save the
source_config.ts
file.
Update the stack configuration
To update the stack configuration for the event consumer SDK, update the configuration in the stages
variable by doing the following:
- In the
buy-with-prime-event-hydrator
repository, in theconfiguration
directory, open thestack_config.ts
file. - Change the value for the
stageName
property to your choice of stage. For example, consider usingstaging
for testing andprod
for going live with shoppers. - If you're testing and want to view debug logs in the AWS CloudWatch console, change the
logLevel
property toStageLogLevel.DEBUG
. If you're going live with shoppers, change theisProd
property totrue
. - In the AWS Management Console, from the menu in the upper right corner, copy your AWS account ID.
- In the
stack_config.ts
file, for theaccount
property, replace<AWS_ACCOUNT_ID>
with your AWS account ID. - In the
region
property, replace<AWS_REGION>
with the region where you want to deploy the event consumer SDK. - In the
destinationConfig
property, remove any destinations that you want to avoid using. - Save the
stack_config.ts
file.
Deploy the event consumer SDK
After you configure the code for your SDK, do the following to deploy the stack to your AWS account:
- Open a command prompt window, and then change directory to the root directory of the
buy-with-prime-event-hydrator
repository. - Run
npm install
. If an error occurs, do the following:- Verify that NPM is installed.
- Verify that you surrounded with quotation marks the values that you copied while configuring the event consumer SDK.
- Verify that you avoided deleting any trailing commas.
- Run
cdk synth
. If an error occurs, verify that the AWS CDK CLI tool is installed. - Run
cdk deploy
. If an error occurs, do the following:- Verify that you authenticated the IAM user to the AWS CDK CLI.
- Verify that the IAM user has permissions to deploy an AWS CloudFormation stack, permissions to create secret values in AWS Secrets Manager, and permissions to create queues in Amazon Simple Queue Service (Amazon SQS).
Verify the deployment
After running cdk deploy
, verify that the AWS CloudFormation stack exists in your AWS instance by doing the following:
- In the AWS Management Console, navigate to AWS CloudFormation.
- Click the
BwpEventConsumerSdkStack-stageName
stack, wherestageName
is the value you specified forstageName
in thestack_config.ts
file. - Verify that the status of the stack automatically updates to become
CREATE_COMPLETE
orUPDATE_COMPLETE
.
Troubleshooting: Destination doesn't receive order updates
If the destination that you configured in the event consumer SDK doesn't receive order updates, deploy the SDK with isProd
set to false
, and logLevel
set to StageLogLevel.DEBUG
, and then check the AWS CloudWatch logs.
View the AWS CloudWatch logs
To view the AWS CloudWatch logs, do the following:
- In the AWS Management Console, navigate to AWS CloudWatch.
- In the navigation, under Logs, choose Log groups.
- Find the log group for the destination and stage that you want to investigate. See the following names of the log groups for prebuilt destinations, where
stageName
is the value that you specified for thestageName
property in thestack_config.ts
file:- Amazon S3:
/aws/lambda/s3-destination-lambda-stageName
- Salesforce Commerce Cloud:
/aws/lambda/sfcc-destination-labmda-stageName
- Salesforce OMS:
/aws/lambda/sf-oms-destination-lambda-stageName
- Amazon S3:
- Click the log group for the destination that you want to troubleshoot.
- Under the Log Streams table, click the log stream with the most recent Last event time, which is often the first event in the list.
- When reviewing the logs, browse the
ERROR
logs first.
Troubleshooting: Larger batch size for Amazon SQS isn't supported
If you configure the Amazon SQS batch size in lib/constructs/sf_oms_destination_infrastructure.ts
, avoid configuring the batch size to a value greater than 20. The Salesforce implementation handles a maximum of 20 events at a time.
Related topics
Updated 16 days ago