Serverless offline + DynamoDb 本地问题
Serverless offline + DynamoDb local issue
我最近一直在玩 serverless offline 和 dynamodb local。
当我使用 websockets 时 - 一切正常。
然后,我决定将协议更改为 http。不知道这之间有何关联,但这是我在代码中所做的唯一更改。
现在,我收到来自 dynamodb 的错误(包括 db 命令的输出):
Serverless: [AWS dynamodb 400 0.034s 0 retries] query({
TableName: 'DEVICE_TABLE_DEV',
KeyConditionExpression: '#id = :id',
ExpressionAttributeNames: { '#id': 'deviceId' },
ExpressionAttributeValues: { ':id': { S: 'a1173b07-af44-450b-b709-902c0b011df2' } }
})
ResourceNotFoundException: Cannot do operations on a non-existent table
我用命令检查了现有的 tables:
aws dynamodb list-tables --endpoint-url http://localhost:8042
我看到 table 存在:
{
"TableNames": [
"DEVICE_TABLE_DEV",
"USER_TABLE_DEV"
]
}
然后我打印了 dynamodb 客户端,我看到,根据文档,提供的选项似乎是正确的:
DocumentClient {
options: {
region: 'localhost',
endpoint: 'http://localhost:8042',
attrValue: 'S6'
},
service: Service {
config: Config {
credentials: [SharedIniFileCredentials],
credentialProvider: [CredentialProviderChain],
region: 'localhost',
logger: [CLI],
apiVersions: {},
apiVersion: null,
endpoint: 'http://localhost:8042',
httpOptions: [Object],
maxRetries: undefined,
maxRedirects: 10,
paramValidation: true,
sslEnabled: true,
s3ForcePathStyle: false,
s3BucketEndpoint: false,
s3DisableBodySigning: true,
s3UsEast1RegionalEndpoint: 'legacy',
s3UseArnRegion: undefined,
computeChecksums: true,
convertResponseTypes: true,
correctClockSkew: false,
customUserAgent: null,
dynamoDbCrc32: true,
systemClockOffset: 0,
signatureVersion: null,
signatureCache: true,
retryDelayOptions: {},
useAccelerateEndpoint: false,
clientSideMonitoring: false,
endpointDiscoveryEnabled: undefined,
endpointCacheSize: 1000,
hostPrefixEnabled: true,
stsRegionalEndpoints: 'legacy'
},
endpoint: Endpoint {
protocol: 'http:',
host: 'localhost:8042',
port: 8042,
hostname: 'localhost',
pathname: '/',
path: '/',
href: 'http://localhost:8042/'
},
_events: { apiCallAttempt: [Array], apiCall: [Array] },
MONITOR_EVENTS_BUBBLE: [Function: EVENTS_BUBBLE],
CALL_EVENTS_BUBBLE: [Function: CALL_EVENTS_BUBBLE],
_clientId: 1
},
attrValue: 'S6'
}
这是我创建客户端的方式:
const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'localhost', endpoint: 'http://localhost:8042'});
更新: 添加我的 serverless.yml dynamodb 部分配置:
dynamodb:
# If you only want to use DynamoDB Local in some stages, declare them here
stages:
- local
start:
port: 8042
inMemory: true
heapInitial: 200m
heapMax: 1g
migrate: true
seed: true
convertEmptyValues: true
# Uncomment only if you already have a DynamoDB running locally
noStart: true
非常感谢这方面的任何建议。
你不应该用 region: 'localhost'
.
初始化 DynamoDB
将其保留或更改为适当的区域,例如:
const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-2', endpoint: 'http://localhost:8042'});
我最近一直在玩 serverless offline 和 dynamodb local。 当我使用 websockets 时 - 一切正常。 然后,我决定将协议更改为 http。不知道这之间有何关联,但这是我在代码中所做的唯一更改。
现在,我收到来自 dynamodb 的错误(包括 db 命令的输出):
Serverless: [AWS dynamodb 400 0.034s 0 retries] query({
TableName: 'DEVICE_TABLE_DEV',
KeyConditionExpression: '#id = :id',
ExpressionAttributeNames: { '#id': 'deviceId' },
ExpressionAttributeValues: { ':id': { S: 'a1173b07-af44-450b-b709-902c0b011df2' } }
})
ResourceNotFoundException: Cannot do operations on a non-existent table
我用命令检查了现有的 tables:
aws dynamodb list-tables --endpoint-url http://localhost:8042
我看到 table 存在:
{
"TableNames": [
"DEVICE_TABLE_DEV",
"USER_TABLE_DEV"
]
}
然后我打印了 dynamodb 客户端,我看到,根据文档,提供的选项似乎是正确的:
DocumentClient {
options: {
region: 'localhost',
endpoint: 'http://localhost:8042',
attrValue: 'S6'
},
service: Service {
config: Config {
credentials: [SharedIniFileCredentials],
credentialProvider: [CredentialProviderChain],
region: 'localhost',
logger: [CLI],
apiVersions: {},
apiVersion: null,
endpoint: 'http://localhost:8042',
httpOptions: [Object],
maxRetries: undefined,
maxRedirects: 10,
paramValidation: true,
sslEnabled: true,
s3ForcePathStyle: false,
s3BucketEndpoint: false,
s3DisableBodySigning: true,
s3UsEast1RegionalEndpoint: 'legacy',
s3UseArnRegion: undefined,
computeChecksums: true,
convertResponseTypes: true,
correctClockSkew: false,
customUserAgent: null,
dynamoDbCrc32: true,
systemClockOffset: 0,
signatureVersion: null,
signatureCache: true,
retryDelayOptions: {},
useAccelerateEndpoint: false,
clientSideMonitoring: false,
endpointDiscoveryEnabled: undefined,
endpointCacheSize: 1000,
hostPrefixEnabled: true,
stsRegionalEndpoints: 'legacy'
},
endpoint: Endpoint {
protocol: 'http:',
host: 'localhost:8042',
port: 8042,
hostname: 'localhost',
pathname: '/',
path: '/',
href: 'http://localhost:8042/'
},
_events: { apiCallAttempt: [Array], apiCall: [Array] },
MONITOR_EVENTS_BUBBLE: [Function: EVENTS_BUBBLE],
CALL_EVENTS_BUBBLE: [Function: CALL_EVENTS_BUBBLE],
_clientId: 1
},
attrValue: 'S6'
}
这是我创建客户端的方式:
const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'localhost', endpoint: 'http://localhost:8042'});
更新: 添加我的 serverless.yml dynamodb 部分配置:
dynamodb:
# If you only want to use DynamoDB Local in some stages, declare them here
stages:
- local
start:
port: 8042
inMemory: true
heapInitial: 200m
heapMax: 1g
migrate: true
seed: true
convertEmptyValues: true
# Uncomment only if you already have a DynamoDB running locally
noStart: true
非常感谢这方面的任何建议。
你不应该用 region: 'localhost'
.
将其保留或更改为适当的区域,例如:
const dynamo = new AWS.DynamoDB.DocumentClient({ region: 'eu-west-2', endpoint: 'http://localhost:8042'});