IDプールの作成
Cognito > IDプール管理 > 新しいIDプールの作成
認証時のロール、未認証時のロールがcognitoによって作成される
IAM権限設定
用途に合わせて認証時のロールまたは、未認証時のロールにInvokeFunction権限を付与する
javascript(ES6)
const { CognitoIdentityClient } = require("@aws-sdk/client-cognito-identity");
const { fromCognitoIdentityPool } = require("@aws-sdk/credential-provider-cognito-identity");
const client_lambda = require("@aws-sdk/client-lambda");
const REGION = "ap-northeast-1";
const lambda = new client_lambda.Lambda({
region: REGION,
credentials: fromCognitoIdentityPool({
client: new CognitoIdentityClient({ region: REGION }),
identityPoolId: "(cognito_pool_id)",
})
});
let param = {
FunctionName: '(lambda_function_name)',
Payload: JSON.stringify({ aaa: 'aaa', bbb: 'bbb' }),
InvocationType: 'RequestResponse'
};
lambda.invoke(param, (err, data) => {
if (err) {
console.log(err, err.stack);
}
let resp = JSON.parse((new TextDecoder).decode(new Uint8Array(data.Payload)));
console.log(resp);
})
あとはwebpackとかでいい感じにしてからブラウザで実行