我最近将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中设置分析区域的属性。请帮忙!
答案 0 :(得分:1)
我认为你的aws_exports文件中缺少'aws_mobile_analytics_app_region'。也许您可以重新下载以查看是否有效或将其硬编入该文件。请检查此code