【问题标题】:Amplify AWSAnalyticsProvider record session fails due to missing AWS region由于缺少 AWS 区域,Amplify AWSAnalyticsProvider 记录会话失败
【发布时间】:2018-03-31 09:07:24
【问题描述】:

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

 // 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 中设置分析区域的属性。请帮忙!

【问题讨论】:

    标签: javascript ionic-framework aws-mobilehub aws-amplify aws-pinpoint


    【解决方案1】:

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

    【讨论】:

    • 非常感谢。确实将“aws_mobile_analytics_app_region”添加到导出文件中是可行的。但是,我需要使用“us-east-1”作为值而不是预期的“eu-central-1”,因为 Amazon Pinpoint 在其他区域尚不可用。使用 Amplify 进行分析现在对我有用。荣誉强大23!
    猜你喜欢
    • 2021-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 2015-11-20
    • 2014-02-25
    • 2011-12-29
    • 1970-01-01
    相关资源
    最近更新 更多