To use the QClojure Braket backend, you need to configure AWS credentials that have permissions to access Amazon Braket and S3 services.
Install and configure the AWS CLI:
# Install AWS CLI (if not already installed)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Configure credentials
aws configure
You'll be prompted for:
us-east-1
(recommended for Braket)json
(recommended)Set environment variables in your shell or application:
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_DEFAULT_REGION="us-east-1"
For persistent configuration, add these to your ~/.bashrc
or ~/.zshrc
:
# Add to ~/.bashrc or ~/.zshrc
export AWS_ACCESS_KEY_ID="your-access-key-id"
export AWS_SECRET_ACCESS_KEY="your-secret-access-key"
export AWS_DEFAULT_REGION="us-east-1"
When running on AWS infrastructure (EC2, Lambda, ECS, etc.), use IAM roles instead of access keys:
Create ~/.aws/credentials
:
[default]
aws_access_key_id = your-access-key-id
aws_secret_access_key = your-secret-access-key
[braket-profile]
aws_access_key_id = your-braket-specific-access-key
aws_secret_access_key = your-braket-specific-secret-key
And ~/.aws/config
:
[default]
region = us-east-1
output = json
[profile braket-profile]
region = us-east-1
output = json
Your AWS credentials need the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"braket:GetDevice",
"braket:GetQuantumTask",
"braket:SearchDevices",
"braket:CreateQuantumTask",
"braket:CancelQuantumTask",
"braket:GetDeviceAvailability"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::your-braket-results-bucket",
"arn:aws:s3:::your-braket-results-bucket/*"
]
},
{
"Effect": "Allow",
"Action": [
"pricing:GetProducts",
"pricing:DescribeServices"
],
"Resource": "*"
}
]
}
aws iam create-user --user-name braket-user
Save the permissions JSON above to braket-policy.json
, then:
aws iam create-policy \
--policy-name BraketAccessPolicy \
--policy-document file://braket-policy.json
aws iam attach-user-policy \
--user-name braket-user \
--policy-arn arn:aws:iam::YOUR-ACCOUNT-ID:policy/BraketAccessPolicy
aws iam create-access-key --user-name braket-user
Save the returned access key ID and secret access key securely.
# List existing access keys
aws iam list-access-keys --user-name braket-user
# Create new access key
aws iam create-access-key --user-name braket-user
# Update your applications with new key
# Then delete old key
aws iam delete-access-key --user-name braket-user --access-key-id OLD-KEY-ID
Cause: Expired or incorrect credentials Solution:
Cause: Missing Braket permissions Solution:
Cause: Missing S3 permissions or incorrect bucket name Solution:
Test your AWS credentials:
# Test basic AWS access
aws sts get-caller-identity
# Test Braket access
aws braket search-devices
# Test S3 access (replace with your bucket name)
aws s3 ls s3://your-braket-results-bucket
us-east-1
us-west-1
and eu-west-2
Once credentials are configured, use them in your QClojure code:
;; Using default credentials (from CLI, environment, or IAM role)
(def backend
(braket/create-braket-simulator {:s3-bucket "your-bucket-name"}))
;; Using specific profile
(def backend
(braket/create-braket-backend {:aws-profile "braket-profile"
:s3-bucket "your-bucket-name"}))
;; Using specific region
(def backend
(braket/create-braket-simulator {:s3-bucket "your-bucket-name"
:region "us-west-1"}))
The QClojure Braket backend will automatically pick up your AWS credentials from any of the configured sources above.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |