Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Thing: Unauthenticated access is not supported for this identity pool. #3613

Closed
mbahmani90 opened this issue Jul 18, 2024 · 2 comments
Labels
iot Issues with the AWS Android SDK for Internet of Things (IoT) question General question

Comments

@mbahmani90
Copy link

Hi,

Hope you are all well.

I want to create thing via android kotlin.

Kotlin Code:

    fun initAWSIotClient(context: Context) {
        val credentialsProvider = CognitoCachingCredentialsProvider(
            context,
            "MY_USER_POOL_ID",
            MY_REGION 
        )
        iotClient = AWSIotClient(credentialsProvider)

        createThing("MyNewThing")
    }

    private fun createThing(thingName: String) {
        Thread {
            try {
                val createThingRequest = CreateThingRequest()
                createThingRequest.thingName = thingName

                val createThingResult = iotClient.createThing(createThingRequest)
                app.l("Thing created: ${createThingResult.thingName}")
            } catch (e: Exception) {
                app.l("Error creating thing: $e")
            }

        }.start()
    }

However, I receive error:

Failure to get credentials

com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Unauthenticated access is not supported for this identity pool. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: xxxxx)

I also added different permissions to the IAM role like AWSIoTFullAccess, AWSIoTThingsRegistration, and test custom policy:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"iot:CreateThing",
				"iot:DescribeThing",
				"iot:DeleteThing"
			],
			"Resource": "*"
		}
	]
}

I have also check Cognito -> user pool -> user access and the role has been applied there. However, the error persists. Do you know how I should solve the error?

dependencies:

    implementation 'com.amazonaws:aws-android-sdk-iot:2.75.2'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.75.2'

    implementation 'com.amplifyframework:core:2.16.0'
    implementation 'com.amplifyframework:aws-api:2.16.0'
    implementation 'com.amplifyframework:aws-datastore:2.16.0'

    implementation 'com.amazonaws:aws-android-sdk-ddb:2.73.0'
    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.75.2'
    implementation 'com.amazonaws:aws-android-sdk-auth-core:2.75.2'

    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.75.2'

    implementation 'com.amplifyframework:aws-auth-cognito:2.16.0'
    implementation("io.github.jan-tennert.supabase:postgrest-kt:0.7.6")
    implementation("io.ktor:ktor-client-cio:2.3.3")

    implementation 'com.amplifyframework:aws-storage-s3:2.16.0'

    implementation("aws.sdk.kotlin:dynamodb:1.0.30")
    implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
    implementation("aws.smithy.kotlin:http-client-engine-okhttp:1.0.11")
    implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")

    implementation 'aws.sdk.kotlin:aws-core:1.0.44'

Thank you.

@lawmicha
Copy link
Contributor

Hi @mbahmani90, did you enable "Allow unauthenticated access" in the Cognito Identity Pool? (not the Cognito User Pool options)

@lawmicha lawmicha added question General question iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor closing soon Issue will auto-close if there is no additional activity within 7 days. labels Jul 22, 2024
@github-actions github-actions bot removed pending-community-response Issue is pending response from the issue requestor closing soon Issue will auto-close if there is no additional activity within 7 days. labels Aug 16, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iot Issues with the AWS Android SDK for Internet of Things (IoT) question General question
Projects
None yet
Development

No branches or pull requests

3 participants