由于缺少 AWS 区域,放大 AWSAnalyticsProvider 记录会话失败

Amplify AWSAnalyticsProvider record session fails due to missing AWS region

我最近将 AWS Amplify Javascript 库与我现有的 Ionic project 集成在一起。使用 Cognito 的身份验证工作正常。但是,当我将日志级别设置为 Amplify.Logger.LOG_LEVEL = 'VERBOSE'; 时,我可以看到 AWS Analytics 由于配置中缺少区域而尚未运行。我有一个相关的 Mobile Hub 项目,它启用了分析,并且项目中的集成 aws-exports.js 看起来像这样(ids 等替换为 <> 占位符):

 // WARNING: DO NOT EDIT. This file is Auto-Generated by AWS Mobile Hub.    It will be overwritten.

// Copyright 2017 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.

// AWS Mobile Hub Project Constants
const awsmobile = {
aws_app_analytics : 'enable',
aws_cognito_identity_pool_id : 'eu-central-1:<>',
aws_cognito_region : 'eu-central-1',
aws_content_delivery : 'enable',
aws_content_delivery_bucket : '<>',
aws_content_delivery_bucket_region : 'eu-central-1',
aws_content_delivery_cloudfront : 'enable',
aws_content_delivery_cloudfront_domain : '<>',
aws_mandatory_sign_in : 'enable',
aws_mobile_analytics_app_id : '<>',
aws_project_id : '<>',
aws_project_name : 'Let Me Go',
aws_project_region : 'eu-central-1',
aws_push_pinpoint : 'enable',
aws_resource_name_prefix : '<>',
aws_sign_in_enabled : 'enable',
aws_user_files : 'enable',
aws_user_files_s3_bucket : '<>',
aws_user_files_s3_bucket_region : 'eu-central-1',
aws_user_pools : 'enable',
aws_user_pools_id : '<>',
aws_user_pools_mfa_type : 'OFF',
aws_user_pools_web_client_id : '<>',
aws_user_settings : 'enable',
}

export default awsmobile;
var AWS = require('aws-sdk');
AWS.config.region = awsmobile.aws_project_region;
AWS.config.update({customUserAgent: 'MobileHub v0.1'});

然后在代码中,我使用导出的 aws-export.js 初始化 Amplify,如下所示:

import Amplify from 'aws-amplify';
import aws_exports from '../assets/js/aws-exports';
Amplify.configure(aws_exports);

运行 该应用程序出现以下错误:

Object { "[DEBUG] 37:44.28 AuthClass - Load credentials successfully": {…} }
ConsoleLogger.js:100
Object { "[DEBUG] 37:44.28 AnalyticsClass - set credentials for analytics": {…} }
ConsoleLogger.js:100
[DEBUG] 37:44.30 AWSAnalyticsProvider - configure Analytics": Object {      appId: "<>", region: undefined, clientInfo: {…}, … }
ConsoleLogger.js:100
[DEBUG] 37:46.980 AWSAnalyticsProvider - init clients
ConsoleLogger.js:84
[INFO] 37:46.980 Cache - Get item: key is <> with options undefined
ConsoleLogger.js:84
Object { "[DEBUG] 37:46.982 AWSAnalyticsProvider - endpointId from cache": […] }
ConsoleLogger.js:100
Object { "[DEBUG] 37:46.990 AWSAnalyticsProvider - demographic user id: ": "<>" }
ConsoleLogger.js:100
Object { "[DEBUG] 37:46.992 AWSAnalyticsProvider - updateEndpoint with params: ": {…} }
ConsoleLogger.js:100
Object { "[DEBUG] 37:46.996 AWSAnalyticsProvider - Pinpoint ERROR": ConfigError: Missing region in config }

所以有两次缺失区域错误,我也可以看到该区域是空的。尽管这听起来很容易,但我无法找出可以在 aws-export.js 中设置分析区域的 属性。请帮忙!

我认为您的 aws_exports 文件中缺少 'aws_mobile_analytics_app_region'。也许您可以重新下载以查看是否有效或将其硬编码到该文件中。检查这个 code