我试图将文件上传到使用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'.
据我所知,环境与此处描述的资源环境有关: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
任何帮助将不胜感激。
答案 0 :(得分:0)
尝试将env
传递到Bucket Stack道具中。
代码段:
在对堆栈进行贴花处理时,该文件夹应位于bin
文件夹下。
const myEnv = {
account: '123456789',
region: 'us-east-1',
};
const App = new cdk.App();
new S3Stack(App, 'S3Stack',{env: myEnv});
答案 1 :(得分:0)
您可能应该为in the cli guide
的CLI配置环境。