Not able to import AWSSecretsManager in iOS project
Expected behavior
I am trying to integrate AWSSecretsManager into an iOS application. I am using Swift package manager to integrate AWS swift sdk. But when we try to import the AWSSecretsManager we get an error "No such module AWSSecretsManager". Is there any solution for this issue
Actual behavior
User should be able to import the "AWSSecretsManager" after integrating the AWS swift sdk
Steps to reproduce
1.create a new project in Xcode
2.Add the SDKs using swift package manager "https://github.com/awslabs/aws-sdk-swift"
3.import AWSSecretsManager in a viewcontroller and build the project. we will be getting an error "No such module AWSSecretsManager"
Logs / stacktrace (if applicable)
No response
Which SDK were you using?
Swift
Which OS were you using?
macOS
SDK version
No response
OS version
14.3.1
This is curious. I can see the AWSSecretsManager files in the build directory, but you're right that importing it fails. I'm getting the SDK dev team involved.
@JibuKThomas
Did you add the AWSSecretManager module in the list of modules to be linked with your target ?
There is a step missing in your list between 2. and 3.
Even with the target's dependencies updated, I still get the error. That is, my test project has this in its package file:
targets: [
.executableTarget(
name: "TargetName",
dependencies: [
.product(name: "AWSSecretsManager", package: "aws-sdk-swift")
],
path: "Sources"),
]
Yet the import AWSSecretsManager still fails.
I just test this and it works. Note that this is an Xcode test, there is no Package.swift involved.
-
Create a CLI project on Xcode
-
Add AWS SDK Package dependency
- Cleanup the list of modules to link, be sure
AWSSecretsManageris present
- write this code
import Foundation
import ClientRuntime
import AWSSecretsManager
@main
struct App {
static func main() async throws {
do {
print("requesting secret")
await SDKLoggingSystem.initialize(logLevel: .warning)
let request = GetSecretValueInput(secretId: "ec2manager-amplify-app-id")
let client = try AWSSecretsManager.SecretsManagerClient(region: "eu-central-1")
let response = try await client.getSecretValue(input: request)
print(response.secretString ?? "no response")
} catch {
print(error)
}
}
}
Works !
Output is
requesting secret
aaabbbcccc
Program ended with exit code: 0
I also wrote a quick test with Package.swift (no xcode involved)
- Create a Swift project
➜ Desktop cd testsdk2
➜ testsdk2 swift package init --type executable
Creating executable package: testsdk2
Creating Package.swift
Creating .gitignore
Creating Sources/
Creating Sources/main.swift
- Write Package.swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "testsdk2",
platforms: [
.macOS(.v13),
],
dependencies: [
.package(url: "https://github.com/awslabs/aws-sdk-swift.git", from: "0.36.0")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "testsdk2",
dependencies: [
.product(name: "AWSSecretsManager", package: "aws-sdk-swift")
]
)
]
)
- write code
@main
struct App {
static func main() async throws {
do {
print("requesting secret")
await SDKLoggingSystem.initialize(logLevel: .warning)
let request = GetSecretValueInput(secretId: "ec2manager-amplify-app-id")
let client = try AWSSecretsManager.SecretsManagerClient(region: "eu-central-1")
let response = try await client.getSecretValue(input: request)
print(response.secretString ?? "no response")
} catch {
print(error)
}
}
}
- run and enjoy !
➜ testsdk2 swift run
Building for debugging...
[562/562] Linking testsdk2
Build complete! (16.82s)
requesting secret
aaabbbccc
I'm very confused why it doesn't work for me... strange.
Oh. AWSSecretsManager isn't part of the AWS SDK for Swift at all. It's from the older AWS iOS SDK.
Hello @shepazon, This is incorrect, AWSSecretsManager is part of the AWS SDK for Swift See this package https://github.com/awslabs/aws-sdk-swift/tree/main/Sources/Services/AWSSecretsManager
Fah. I knew this. I'm just not used to seeing the client class references prefixed with the package name in the code; I would have written this line:
let client = try AWSSecretsManager.SecretsManagerClient(region: "eu-central-1")
Instead as:
let client = try SecretsManagerClient(region: "eu-central-1")
Sorry about that. I think we even went through this exact conversation once before. :)