typescript - 使用 CDK 将文件上传到 S3 存储桶
问题描述
我正在尝试将文件上传到使用 CDK 创建的 S3 存储桶,但是即使使用 AWS 提供的示例代码,我也始终遇到相同的错误。
这是堆栈。
export class TestStack extends cdk.Stack {
public readonly response: string;
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const websiteBucket = new s3.Bucket(this, 'WebsiteBucket', {
websiteIndexDocument: 'index.html',
publicReadAccess: true,
});
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
sources: [s3deploy.Source.asset('./website-dist')],
destinationBucket: websiteBucket,
destinationKeyPrefix: 'web/static' // optional prefix in destination bucket
});
}
}
这是所要求的主箱
const app = new cdk.App();
new TestStack(app, "TestStack", {
env: {
account: '123456789',
region: 'us-east-1',
}
});
在destinationBucket
Visual Studio 代码中和运行 npm build 时提供以下错误
Property 'env' is missing in type 'Bucket' but required in type 'IBucket'.
据我所知,env 与此处描述的资源环境有关:https ://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.ResourceEnvironment.html
我无法弄清楚如何将它提供给存储桶对象,因为它似乎没有出现在此处描述的可用输入道具上:https ://docs.aws.amazon.com/cdk/api/latest/docs/@aws -cdk_aws-s3.Bucket.html
任何帮助将不胜感激。
解决方案
尝试传入env
Bucket Stack 道具。
代码片段:
bin
当您贴花堆栈时,它应该位于文件夹下。
const myEnv = {
account: '123456789',
region: 'us-east-1',
};
const App = new cdk.App();
new S3Stack(App, 'S3Stack',{env: myEnv});
推荐阅读
- angularjs - 我很难运行 $apply
- css - By using Bootstrap 4, how to toggle a div whose parent div is hidden under the certain resolution?
- json - Azure Policy 开启防火墙
- html - 更改 Keycloak 登录的标题
- python - 无法复制列表并修改副本而不修改原始列表
- c - 指向作为结构本身的结构的指针
- php - 在 Yii2 面包屑小部件中更改主页文本和 URL
- ios - iOS 上虚幻引擎中的透明背景
- javascript - Increase HTML5 Canvas Resolution
- python - 如何在启动 20 秒后启动 bash 脚本?