AWS CLI를 사용한 Amazon Cognito Identity 예제 - AWS Command Line Interface

이 문서는 AWS CLI의 버전 1에만 해당합니다. AWS CLI의 버전 2와 관련된 문서는 버전 2 사용 설명서를 참조하세요.

AWS CLI를 사용한 Amazon Cognito Identity 예제

다음 코드 예제에서는 Amazon Cognito 자격 증명에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여 줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예제에는 컨텍스트에서 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있는 전체 소스 코드에 대한 링크가 포함되어 있습니다.

주제

작업

다음 코드 예제에서는 create-identity-pool을 사용하는 방법을 보여 줍니다.

AWS CLI

Cognito 자격 증명 풀 공급자를 사용하여 자격 증명 풀 생성

이 예시에서는 MyIdentityPool이라는 자격 증명 풀을 생성합니다. Cognito 자격 증명 풀 공급자가 있습니다. 인증되지 않은 자격 증명은 허용되지 않습니다.

명령:

aws cognito-identity create-identity-pool --identity-pool-name MyIdentityPool --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_aaaaaaaaa",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

출력:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

다음 코드 예제에서는 delete-identities을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀 삭제

이 예제에서는 자격 증명 풀을 삭제합니다.

명령:

aws cognito-identity delete-identity-pool --identity-ids-to-delete "us-west-2:11111111-1111-1111-1111-111111111111"

출력:

{ "UnprocessedIdentityIds": [] }
  • API 세부 정보는 AWS CLI 명령 참조의 DeleteIdentities 섹션을 참조하세요.

다음 코드 예제에서는 delete-identity-pool을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀 삭제

다음 delete-identity-pool 예시에서는 지정된 자격 증명 풀을 삭제합니다.

명령:

aws cognito-identity delete-identity-pool \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

이 명령은 출력을 생성하지 않습니다.

다음 코드 예제에서는 describe-identity-pool을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀을 설명하는 방법

이 예제에서는 자격 증명 풀을 설명합니다.

명령:

aws cognito-identity describe-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

출력:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }

다음 코드 예제에서는 get-identity-pool-roles을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀 역할을 가져오는 방법

이 예제에서는 자격 증명 풀이 나열되어 있습니다.

명령:

aws cognito-identity get-identity-pool-roles --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111"

출력:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "Roles": { "authenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role", "unauthenticated": "arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolUnauth_Role" } }

다음 코드 예제에서는 list-identity-pools을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀 나열

이 예시에는 자격 증명 풀이 나열되어 있습니다. 최대 20개의 자격 증명이 나열되어 있습니다.

명령:

aws cognito-identity list-identity-pools --max-results 20

출력:

{ "IdentityPools": [ { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "AnotherIdentityPool" }, { "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "IdentityPoolRegionA" } ] }
  • API 세부 정보는 AWS CLI 명령 참조의 ListIdentityPools 섹션을 참조하세요.

다음 코드 예제에서는 set-identity-pool-roles을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀 역할을 설정하는 방법

다음 set-identity-pool-roles 예제에서는 자격 증명 풀의 역할을 설정합니다.

aws cognito-identity set-identity-pool-roles \ --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" \ --roles authenticated="arn:aws:iam::111111111111:role/Cognito_MyIdentityPoolAuth_Role"

다음 코드 예제에서는 update-identity-pool을 사용하는 방법을 보여 줍니다.

AWS CLI

자격 증명 풀을 생성하는 방법

이 예제에서는 자격 증명 풀을 업데이트합니다. 이름을 MyIdentityPool로 설정합니다. 자격 증명 공급자로 Cognito를 추가합니다. 인증되지 않은 자격 증명은 허용되지 않습니다.

명령:

aws cognito-identity update-identity-pool --identity-pool-id "us-west-2:11111111-1111-1111-1111-111111111111" --identity-pool-name "MyIdentityPool" --no-allow-unauthenticated-identities --cognito-identity-providers ProviderName="cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111",ClientId="3n4b5urk1ft4fl3mg5e62d9ado",ServerSideTokenCheck=false

출력:

{ "IdentityPoolId": "us-west-2:11111111-1111-1111-1111-111111111111", "IdentityPoolName": "MyIdentityPool", "AllowUnauthenticatedIdentities": false, "CognitoIdentityProviders": [ { "ProviderName": "cognito-idp.us-west-2.amazonaws.com/us-west-2_111111111", "ClientId": "3n4b5urk1ft4fl3mg5e62d9ado", "ServerSideTokenCheck": false } ] }
  • API 세부 정보는 AWS CLI 명령 참조의 UpdateIdentityPool 섹션을 참조하세요.