代码拉取完成,页面将自动刷新
###############################################################################
# Copyright 2020 ShenZhen Xiaoniu New Energy Inc. All Rights Reserved. #
# Author: saico@mosf.cn #
###############################################################################
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'escharger awsIoT sam server'
Parameters:
TimeZone:
Type: String
Default: Asia/Shanghai
MaxResults:
Type: Number
Default: 24
RestoreUserid:
Type: String
Default: NONE
DefaultThingType:
Type: String
Default: XNEVBK
DefaultGuestok:
Type: String
Default: 1
DefaultGunstandard:
Type: String
Default: 0
OTAVersion:
Type: String
Default: 1.3.3
OTxVersion:
Type: String
Default: 2.3.9
FirstChargerID:
Type: Number
Default: 100000
# 一定要记得修改config.js中的策略文档模板 POLICY_DOCUMENT
# 以下是中国宁夏和韩国的配置参数
# 在运行 sam build, sam deploy --guided 之前,请注意先创建事物类型,命令如下:
# aws iot create-thing-type \
# --thing-type-name "XNEVBK" \
# --thing-type-properties "thingTypeDescription=Created by ShenZhen Xiaoniu Company (www.mosf.cn),searchableAttributes=chargerid,connected,onltime"
# sam deploy --guided 所有参数都用默认,iotappFunction may not have authorization defined, Is this okay? 除外,必需要回答y
# sam deploy 部署完成后,可根据实际情况变更参数,入口:AWSConsole -> Lambda -> Function(函数) -> (one of function,选择一个函数) -> 配置 -> 环境变量
# 每个函数的使用变量不尽相同,根据实际需要设置
# 注意:固件已内置了初始化事物名称(xniotevesps2)及证书,设备第一次开机会自动连接到AWSIoT并且立即更新私有证书及事物名称
# 服务器务必先准备好初始化事物,并且绝对永久不允许变更,修改或删除(有效期为50年)
# evcharger_awsIoT_vue 这个项目需要修改的位置是:
# 1. go.sh 修改部署的s3bucket, 这个变量是指html页面在S3的部署位置,所以需要事先创建这个Bucket,这个bucketname是一个域名,域名和S3存储映射的方法请自行搜索
# 2. config.js 在evcharger_awsIoT_sam部署成功后,到Console->APIGateWay中找到HttpApi的域名地址,到本项目中修改 部署 测试
Globals:
Function:
CodeUri: apps/
Runtime: nodejs18.x
Layers:
- !Ref elayer
Resources:
etask:
Type: AWS::Serverless::Function
Properties:
Timeout: 30
Role: !GetAtt erole.Arn
Handler: esptask.mainHandler
Events:
evt0:
Type: SQS
Properties:
# hk=ap-east-1 kr=ap-northeast-2
# Queue: arn:aws:sqs:ap-east-1:264381684832:espQUEUE
Queue: arn:aws:sqs:ap-northeast-2:264381684832:espQUEUE
Environment:
Variables:
Time_Zone: !Ref TimeZone
Default_ThingType: !Ref DefaultThingType
erule:
Type: AWS::Serverless::Function
Description: Code for IoT Rule
Properties:
Timeout: 30
Role: !GetAtt erole.Arn
Handler: esprule.mainHandler
Events:
edtos:
Type: IoTRule
Properties:
Sql: SELECT *,topic(3) as reportmac FROM 'xniot/dtos/+'
econn:
Type: IoTRule
Properties:
Sql: SELECT *,topic(5) as connevent FROM '$aws/events/presence/+/+'
Environment:
Variables:
Time_Zone: !Ref TimeZone
Default_ThingType: !Ref DefaultThingType
Default_Guestok: !Ref DefaultGuestok
Default_Gunstandard: !Ref DefaultGunstandard
OTA_Version: !Ref OTAVersion
OTx_Version: !Ref OTxVersion
NEW_ChargerID: !Ref FirstChargerID
ehttp:
Type: AWS::Serverless::Function
Description: HTTP API for Web Client
Properties:
Timeout: 120
Role: !GetAtt erole.Arn
Handler: espapi.mainHandler
Events:
evt0:
Type: HttpApi
Properties:
Path: /{proxy+}
Method: get
ApiId: !Ref egatw
Environment:
Variables:
Time_Zone: !Ref TimeZone
Restore_Userid: !Ref RestoreUserid
Max_Results: !Ref MaxResults
Default_ThingType: !Ref DefaultThingType
OTA_Version: !Ref OTAVersion
OTx_Version: !Ref OTxVersion
egatw:
Type: AWS::Serverless::HttpApi
Properties:
CorsConfiguration:
AllowOrigins:
# - "https://hk.xnexcharger.com"
- "https://kr.xnexcharger.com"
StageName:
elayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: elayer
Description: Dependencies for xniotsam app
ContentUri: dependencies/
CompatibleRuntimes:
- nodejs18.x
LicenseInfo: 'MIT'
RetentionPolicy: Retain
erole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Service:
- s3.amazonaws.com
- sqs.amazonaws.com
- iot.amazonaws.com
- iam.amazonaws.com
- lambda.amazonaws.com
- dynamodb.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: 'xnCustomRole_for_xnsamapp'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- s3:*
- sqs:*
- iot:*
- iam:*
- logs:*
- lambda:*
- dynamodb:*
Resource: '*'
t00evuser:
Type: AWS::DynamoDB::Table
Properties:
TableName: evuser
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: utype
AttributeType: N
- AttributeName: uflag
AttributeType: S
- AttributeName: regtime
AttributeType: S
- AttributeName: lastvisit
AttributeType: S
- AttributeName: ipaddress
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: gsi_uflag
KeySchema:
- AttributeName: utype
KeyType: HASH
- AttributeName: uflag
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
- IndexName: gsi_regtime
KeySchema:
- AttributeName: utype
KeyType: HASH
- AttributeName: regtime
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
- IndexName: gsi_lastvisit
KeySchema:
- AttributeName: utype
KeyType: HASH
- AttributeName: lastvisit
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
- IndexName: gsi_ipaddress
KeySchema:
- AttributeName: ipaddress
KeyType: HASH
Projection:
ProjectionType: KEYS_ONLY
BillingMode: PAY_PER_REQUEST
ProvisionedThroughput:
ReadCapacityUnits: 0
WriteCapacityUnits: 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。