AWSLambda에서 UserPool의 속성 변경
소개
Cognito의 유저 속성에 커스텀 속성으로서 「세이브수」를 등록해, 관리자가 허가하면 그 속성을 수정해, 앱측에서 커스텀 속성을 취득하고 싶다…
정리하면
· AWS Management Console에서 속성 값을 등록하거나 업데이트할 수 없습니다(사용).
・하지만 API로부터라면 보통으로 갱신을 할 수 있다.
・값도 보통으로 취득할 수 있다.
사용자의 맞춤 속성 값을 수정하고 싶습니다.
사용자를 초기 등록 할 때 설정할 수 있습니다.
하지만 수정할 수 없다.
관리 콘솔에 수정할 곳이 있습니까? 라고 생각해 바라봐도… 없다.
그물을 조사하지도 않는다.
Userpool 자체의 초기 등록 방법인가? 라고 생각했지만 그렇지 않은 모습.
애초에 커스텀 속성은 초기 등록시뿐인가? ?
메소드명에 「adminUpdateUserAttributes」라고 하는 것이 있으니까 갱신할 수 있지 않습니까?
라고 생각해, 적어도 API 경유에서도 갱신시켜 줘-라고 생각하면…
aws 포럼 에 있었습니다.
var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [ / required /
{
Name: 'custom:attributename', / required /
Value: 'value'
},
/ more items /
],
UserPoolId: 'ap-southeast-2_abcdefghi', / required /
Username: 'username'/ required /
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
과연 할 수 있구나… 라고 생각해, 해 보았다.
/required/
라고 코멘트는 빼지 않으면 에러가 되는구나…
index.js(lambda)var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [
{
Name: 'custom:SavePoint',
Value: '2'
},
],
UserPoolId: 'ap-northeast-1_hohohoho',
Username: 'hoge'
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
이것만이라면 액세스권이라도 괜찮은가? 라고 생각하면 안의 정롤 정의가 필요했다.
역할을 정의하려면 정책 정의가 필요했습니다.

필요한 정책은 「cognito User Pools」만.
해당 정책과 새로 만든 역할을 연결합니다.
그리고, 상기 함수의 롤로 한다.
실행하면 ...안외 솔직하게 움직였습니다.
커스텀 속성은 number형입니다만, value의 지정은 ''를 붙이는군요.

값이 바뀐 것은 화면에서 확인할 수 있다.
덧붙여 원래 값이 등록되어 있지 않아도 adminUpdateUserAttributes를 사용하면 등록할 수 있다.
값 얻기
이것도 또 미묘하게 귀찮아…
일본어로 작성된 자습서 하지만 있는데, 어쩐지 알기 어렵다.
결국 SDK 샘플 을 보고 작성했다.
hoge.js(clientside)AWS.config.update({
accessKeyId: 'XXXXXXXXX', //IAMのアクセスキーID
secretAccessKey: 'YYYYYYY', //アクセスキーID作成時のみ表示
region:'ap-northeast-1',
IdentityPoolId: 'ap-northeast-1:XX-XXXX-xxxx-xxxx-xx'
});
(signin処理は省略:signin時にアクセストークン取得できる。)
var SavePoint = 0;
var cognitoSP = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
cognitoSP.getUser({AccessToken:data.AuthenticationResult.AccessToken},function(err,data){
if(err) console.log(err,err.stack);
else {
data.UserAttributes.forEach(function(val,id,arary) {
if (val.Name == 'custom:SavePoint') {
SavePoint = val.Value;
}
});
}
});
도중의 「data.AuthenticationResult.AccessToken」에는 액세스 토큰을 넣을 필요가 있다.
액세스 토큰은 signin시에 취득할 수 있다. (여기서는 중간에 접혀있다)
이제 SavePoint에 cognito의 사용자 지정 속성(custom:SavePoint) 값이 포함되었습니다.
마지막으로
의외 간단한 것은 알았지만, 여기까지 오는데 4시간 정도 걸렸다.
값의 변경을 화면에서도 추가, 수정할 수 있게 되면 좀 더 간단하게 되지만.
Reference
이 문제에 관하여(AWSLambda에서 UserPool의 속성 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/damacchi/items/45667eba399d97f7e056
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
· AWS Management Console에서 속성 값을 등록하거나 업데이트할 수 없습니다(사용).
・하지만 API로부터라면 보통으로 갱신을 할 수 있다.
・값도 보통으로 취득할 수 있다.
사용자의 맞춤 속성 값을 수정하고 싶습니다.
사용자를 초기 등록 할 때 설정할 수 있습니다.
하지만 수정할 수 없다.
관리 콘솔에 수정할 곳이 있습니까? 라고 생각해 바라봐도… 없다.
그물을 조사하지도 않는다.
Userpool 자체의 초기 등록 방법인가? 라고 생각했지만 그렇지 않은 모습.
애초에 커스텀 속성은 초기 등록시뿐인가? ?
메소드명에 「adminUpdateUserAttributes」라고 하는 것이 있으니까 갱신할 수 있지 않습니까?
라고 생각해, 적어도 API 경유에서도 갱신시켜 줘-라고 생각하면…
aws 포럼 에 있었습니다.
var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [ / required /
{
Name: 'custom:attributename', / required /
Value: 'value'
},
/ more items /
],
UserPoolId: 'ap-southeast-2_abcdefghi', / required /
Username: 'username'/ required /
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
과연 할 수 있구나… 라고 생각해, 해 보았다.
/required/
라고 코멘트는 빼지 않으면 에러가 되는구나…
index.js(lambda)var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [
{
Name: 'custom:SavePoint',
Value: '2'
},
],
UserPoolId: 'ap-northeast-1_hohohoho',
Username: 'hoge'
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
이것만이라면 액세스권이라도 괜찮은가? 라고 생각하면 안의 정롤 정의가 필요했다.
역할을 정의하려면 정책 정의가 필요했습니다.

필요한 정책은 「cognito User Pools」만.
해당 정책과 새로 만든 역할을 연결합니다.
그리고, 상기 함수의 롤로 한다.
실행하면 ...안외 솔직하게 움직였습니다.
커스텀 속성은 number형입니다만, value의 지정은 ''를 붙이는군요.

값이 바뀐 것은 화면에서 확인할 수 있다.
덧붙여 원래 값이 등록되어 있지 않아도 adminUpdateUserAttributes를 사용하면 등록할 수 있다.
값 얻기
이것도 또 미묘하게 귀찮아…
일본어로 작성된 자습서 하지만 있는데, 어쩐지 알기 어렵다.
결국 SDK 샘플 을 보고 작성했다.
hoge.js(clientside)AWS.config.update({
accessKeyId: 'XXXXXXXXX', //IAMのアクセスキーID
secretAccessKey: 'YYYYYYY', //アクセスキーID作成時のみ表示
region:'ap-northeast-1',
IdentityPoolId: 'ap-northeast-1:XX-XXXX-xxxx-xxxx-xx'
});
(signin処理は省略:signin時にアクセストークン取得できる。)
var SavePoint = 0;
var cognitoSP = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
cognitoSP.getUser({AccessToken:data.AuthenticationResult.AccessToken},function(err,data){
if(err) console.log(err,err.stack);
else {
data.UserAttributes.forEach(function(val,id,arary) {
if (val.Name == 'custom:SavePoint') {
SavePoint = val.Value;
}
});
}
});
도중의 「data.AuthenticationResult.AccessToken」에는 액세스 토큰을 넣을 필요가 있다.
액세스 토큰은 signin시에 취득할 수 있다. (여기서는 중간에 접혀있다)
이제 SavePoint에 cognito의 사용자 지정 속성(custom:SavePoint) 값이 포함되었습니다.
마지막으로
의외 간단한 것은 알았지만, 여기까지 오는데 4시간 정도 걸렸다.
값의 변경을 화면에서도 추가, 수정할 수 있게 되면 좀 더 간단하게 되지만.
Reference
이 문제에 관하여(AWSLambda에서 UserPool의 속성 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/damacchi/items/45667eba399d97f7e056
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
메소드명에 「adminUpdateUserAttributes」라고 하는 것이 있으니까 갱신할 수 있지 않습니까?
라고 생각해, 적어도 API 경유에서도 갱신시켜 줘-라고 생각하면…
aws 포럼 에 있었습니다.
var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [ / required /
{
Name: 'custom:attributename', / required /
Value: 'value'
},
/ more items /
],
UserPoolId: 'ap-southeast-2_abcdefghi', / required /
Username: 'username'/ required /
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
과연 할 수 있구나… 라고 생각해, 해 보았다.
/required/
라고 코멘트는 빼지 않으면 에러가 되는구나…
index.js(lambda)
var AWS = require('aws-sdk');
var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
exports.handler = (event, context, callback) => {
var params = {
UserAttributes: [
{
Name: 'custom:SavePoint',
Value: '2'
},
],
UserPoolId: 'ap-northeast-1_hohohoho',
Username: 'hoge'
};
cognitoidentityserviceprovider.adminUpdateUserAttributes(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
};
이것만이라면 액세스권이라도 괜찮은가? 라고 생각하면 안의 정롤 정의가 필요했다.
역할을 정의하려면 정책 정의가 필요했습니다.

필요한 정책은 「cognito User Pools」만.
해당 정책과 새로 만든 역할을 연결합니다.
그리고, 상기 함수의 롤로 한다.
실행하면 ...안외 솔직하게 움직였습니다.
커스텀 속성은 number형입니다만, value의 지정은 ''를 붙이는군요.

값이 바뀐 것은 화면에서 확인할 수 있다.
덧붙여 원래 값이 등록되어 있지 않아도 adminUpdateUserAttributes를 사용하면 등록할 수 있다.
값 얻기
이것도 또 미묘하게 귀찮아…
일본어로 작성된 자습서 하지만 있는데, 어쩐지 알기 어렵다.
결국 SDK 샘플 을 보고 작성했다.
hoge.js(clientside)AWS.config.update({
accessKeyId: 'XXXXXXXXX', //IAMのアクセスキーID
secretAccessKey: 'YYYYYYY', //アクセスキーID作成時のみ表示
region:'ap-northeast-1',
IdentityPoolId: 'ap-northeast-1:XX-XXXX-xxxx-xxxx-xx'
});
(signin処理は省略:signin時にアクセストークン取得できる。)
var SavePoint = 0;
var cognitoSP = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
cognitoSP.getUser({AccessToken:data.AuthenticationResult.AccessToken},function(err,data){
if(err) console.log(err,err.stack);
else {
data.UserAttributes.forEach(function(val,id,arary) {
if (val.Name == 'custom:SavePoint') {
SavePoint = val.Value;
}
});
}
});
도중의 「data.AuthenticationResult.AccessToken」에는 액세스 토큰을 넣을 필요가 있다.
액세스 토큰은 signin시에 취득할 수 있다. (여기서는 중간에 접혀있다)
이제 SavePoint에 cognito의 사용자 지정 속성(custom:SavePoint) 값이 포함되었습니다.
마지막으로
의외 간단한 것은 알았지만, 여기까지 오는데 4시간 정도 걸렸다.
값의 변경을 화면에서도 추가, 수정할 수 있게 되면 좀 더 간단하게 되지만.
Reference
이 문제에 관하여(AWSLambda에서 UserPool의 속성 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/damacchi/items/45667eba399d97f7e056
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
AWS.config.update({
accessKeyId: 'XXXXXXXXX', //IAMのアクセスキーID
secretAccessKey: 'YYYYYYY', //アクセスキーID作成時のみ表示
region:'ap-northeast-1',
IdentityPoolId: 'ap-northeast-1:XX-XXXX-xxxx-xxxx-xx'
});
(signin処理は省略:signin時にアクセストークン取得できる。)
var SavePoint = 0;
var cognitoSP = new AWS.CognitoIdentityServiceProvider({apiVersion: '2016-04-18'});
cognitoSP.getUser({AccessToken:data.AuthenticationResult.AccessToken},function(err,data){
if(err) console.log(err,err.stack);
else {
data.UserAttributes.forEach(function(val,id,arary) {
if (val.Name == 'custom:SavePoint') {
SavePoint = val.Value;
}
});
}
});
의외 간단한 것은 알았지만, 여기까지 오는데 4시간 정도 걸렸다.
값의 변경을 화면에서도 추가, 수정할 수 있게 되면 좀 더 간단하게 되지만.
Reference
이 문제에 관하여(AWSLambda에서 UserPool의 속성 변경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/damacchi/items/45667eba399d97f7e056텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)