我是 aws 和 React 的新手。昨天我有一些代码正在运行(我可以将数据从 React 页面放入 dynamodb 表中)。今天我尝试创建一个新表(称为“事件”),但我没有让它工作。然后,我使用 git 命令“git reset --hard”回滚所有本地更改,并从 aws 管理系统中删除了表“Events”。现在,当我运行“npx sst start”时,我无法部署该应用程序。错误信息如下:
C:\Users\nickl\padel\notes>npx sst start
Using stage: admin
Preparing your SST app
=======================
Deploying debug stack
=======================
Deploying stacks
✅ admin-notes-debug-stack (no changes)
Stack admin-notes-debug-stack
Status: no changes
Outputs:
BucketArn: arn:aws:s3:::admin-notes-debug-stack-bucket83908e77-1tywtvoiarr1e
BucketName: admin-notes-debug-stack-bucket83908e77-1tywtvoiarr1e
Endpoint: wss://8pi9mbv1qb.execute-api.us-east-1.amazonaws.com/admin
===============
Deploying app
===============
Deploying stacks
Checking deploy status...
admin-notes-storage | UPDATE_IN_PROGRESS | AWS::CloudFormation::Stack | admin-notes-storage | User Initiated
admin-notes-storage | UPDATE_ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | admin-notes-storage | Export admin-notes-storage:ExportsOutputRefEventsTable4B7491D3C6BE5608 cannot be deleted as it is in use by admin-notes-api
Checking deploy status...
admin-notes-storage | UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS | AWS::CloudFormation::Stack | admin-notes-storage
admin-notes-storage | UPDATE_ROLLBACK_COMPLETE | AWS::CloudFormation::Stack | admin-notes-storage
❌ admin-notes-storage failed: Export admin-notes-storage:ExportsOutputRefEventsTable4B7491D3C6BE5608 cannot be deleted as it is in use by admin-notes-api
Stack admin-notes-storage
Status: failed
Error: Export admin-notes-storage:ExportsOutputRefEventsTable4B7491D3C6BE5608 cannot be deleted as it is in use by admin-notes-api
Stack admin-notes-api
Status: not deployed
Stack admin-notes-auth
Status: not deployed
Stack admin-notes-frontend
Status: not deployed
Failed to deploy the app
如果您需要代码中的其他内容,请告诉我。
谢谢
解决方案是从 aws 管理系统中删除所有堆栈,然后重新创建它们。
一个好的做法是首先检查您正在创建的资源是否已经存在于您的阶段中,尤其是在开发过程中。 请注意,如果创建资源时发生任何失败,您将面临堆栈创建失败。 例如,此代码在创建 s3 存储桶之前检查它是否存在:
async function createS3Bucket(stack: any, bucketName: string): Promise<void> {
const s3 = new AWS.S3();
try {
// Check if the bucket already exists
await s3.headBucket({ Bucket: bucketName }).promise();
console.log(`Bucket "${bucketName}" already exists.`);
} catch (error) {
// Bucket doesn't exist, create it
try {
await s3.createBucket({ Bucket: bucketName }).promise();
console.log(`Bucket "${bucketName}" created successfully.`);
} catch (error) {
console.error('Error creating bucket: ', error);
}
}
希望这对您将来有帮助!