You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add support for Bedrock API Key
* add documentation for authentication
* add a test on AWS_BEARER_TOKEN_BEDROCK
* add example
* swift-format
* add license header
Copy file name to clipboardExpand all lines: README.md
+90Lines changed: 90 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,96 @@ Use the `listModels()` function to test your set-up. This function will return a
73
73
let models =tryawait bedrock.listModels()
74
74
```
75
75
76
+
## Authentication
77
+
78
+
The Swift Bedrock Library supports multiple authentication methods to work with Amazon Bedrock. By default, it uses the standard AWS credential provider chain, but you can specify different authentication types when initializing the `BedrockService`.
79
+
80
+
### Default Authentication
81
+
82
+
Uses the standard AWS credential provider chain, which checks for credentials in the following order:
Use a JWT token from an external identity provider (like Sign In with Apple or Google) to assume an IAM role. This is particularly useful for iOS, tvOS, and macOS applications where traditional AWS CLI-based authentication isn't available.
// Optional: Called on main thread when credentials are retrieved
132
+
print("AWS credentials updated")
133
+
}
134
+
)
135
+
)
136
+
```
137
+
138
+
### API Key Authentication
139
+
140
+
Use an API key for authentication. API keys are generated in the AWS console and provide a simpler authentication method for specific use cases.
141
+
142
+
```swift
143
+
let bedrock =tryawaitBedrockService(
144
+
region: .uswest2,
145
+
authentication: .apiKey(key: "your-api-key-here")
146
+
)
147
+
```
148
+
149
+
### Static Credentials Authentication
150
+
151
+
Use static AWS credentials directly. **This method is strongly discouraged for production use** and should only be used for testing and debugging purposes.
**Security Note**: Never hardcode credentials in your source code or commit them to version control. Use environment variables, secure credential storage, or other secure methods to manage credentials in production applications.
165
+
76
166
## Chatting using the Converse or ConverseStream API
Copy file name to clipboardExpand all lines: Sources/BedrockAuthentication.swift
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -24,12 +24,14 @@ import SmithyIdentity
24
24
/// - `webIdentity`: Use a web identity token (JWT) to assume an IAM role. This is useful for applications running on iOS, tvOS or macOS where you cannot use the AWS CLI. Typically, the application authenticates the user with an external Identity provider (such as Sign In with Apple or Login With Google) and receives a JWT token. The application then uses this token to assume an IAM role and receive temporary AWS credentials. Some additional configuration is required on your AWS account to allow this. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_oidc.html for more information. If you use Sign In With Apple, read https://docs.aws.amazon.com/sdk-for-swift/latest/developer-guide/apple-integration.html for more information.
25
25
/// Because `webidentity` is often used by application presenting a user interface. This method of authentication allows you to pass an optional closure that will be called when the credentials are retrieved. This is useful for updating the UI or notifying the user. The closure is called on the main (UI) thread.
26
26
/// - `static`: Use static AWS credentials. We strongly recommend to not use this option in production. This might be useful in some rare cases when testing and debugging.
27
+
/// - `apiKey`: Use an API key to authenticate. This is useful for applications that do not require full AWS credentials and only need to access specific APIs. The API key is passed as a string. API Keys are generated in the AWS console.
0 commit comments