new Function(this, "TestFunction", {
handler: "TestFunction.handler",
code: Code.asset(path.join(__dirname, "lambdas/")),
runtime: Runtime.NodeJS810
});当我尝试将它部署到CodeDeploy时,我得到:
Parameters: [TestFunctionCodeS3Bucket, TestFunctionCodeS3VersionKey] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError;当我检查生成的CloudFormation时,我可以看到参数:
TestFunctionCodeS3Bucket:
Type: String
Description: S3 bucket for asset "AppStack/TestFunction/Code"
TestFunctionCodeS3VersionKey:
Type: String
Description: S3 key for asset version "AppStack/TestFunction/Code"我的理解是,Code.asset应该自己引导这个过程。我是不是错过了一步?
查看docs (https://docs.aws.amazon.com/cdk/latest/guide/serverless_example.html),它声明您应该创建一个Amazon S3 bucket that contains the Lambda function code.,但是在示例中没有任何地方可以显式地看到这一点。所以我以为这是含蓄的。
产生的CFN:
Parameters:
TestFunctionCodeS3BucketE8C956AE:
Type: String
Description: S3 bucket for asset "AppStack/TestFunction/Code"
TestFunctionCodeS3VersionKey6B3F3155:
Type: String
Description: S3 key for asset version "AppStack/TestFunction/Code"
Resources:
TestFunctionServiceRole6ABD93C7:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: "2012-10-17"
ManagedPolicyArns:
- Fn::Join:
- ""
- - "arn:"
- Ref: AWS::Partition
- :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Metadata:
aws:cdk:path: AppStack/TestFunction/ServiceRole/Resource
TestFunction22AD90FC:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket:
Ref: TestFunctionCodeS3BucketE8C956AE
S3Key:
Fn::Join:
- ""
- - Fn::Select:
- 0
- Fn::Split:
- "||"
- Ref: TestFunctionCodeS3VersionKey6B3F3155
- Fn::Select:
- 1
- Fn::Split:
- "||"
- Ref: TestFunctionCodeS3VersionKey6B3F3155
Handler: TestFunction.handler
Role:
Fn::GetAtt:
- TestFunctionServiceRole6ABD93C7
- Arn
Runtime: nodejs8.10
DependsOn:
- TestFunctionServiceRole6ABD93C7
Metadata:
aws:cdk:path: AppStack/TestFunction/Resource
aws:asset:path: /Volumes/Unix/AMCC/src/AMCConsole/packages/infrastructure/lib/lambdas/mars
aws:asset:property: Code
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Modules: aws-cdk=0.22.0,@aws-cdk/assets=0.22.0,@aws-cdk/assets-docker=0.22.0,@aws-cdk/aws-apigateway=0.22.0,@aws-cdk/aws-cloudformation=0.22.0,@aws-cdk/aws-cloudfront=0.22.0,@aws-cdk/aws-cloudwatch=0.22.0,@aws-cdk/aws-codebuild=0.22.0,@aws-cdk/aws-codecommit=0.22.0,@aws-cdk/aws-codepipeline=0.22.0,@aws-cdk/aws-codepipeline-api=0.22.0,@aws-cdk/aws-cognito=0.22.0,@aws-cdk/aws-ec2=0.22.0,@aws-cdk/aws-ecr=0.22.0,@aws-cdk/aws-events=0.22.0,@aws-cdk/aws-iam=0.22.0,@aws-cdk/aws-kms=0.22.0,@aws-cdk/aws-lambda=0.22.0,@aws-cdk/aws-route53=0.22.0,@aws-cdk/aws-s3=0.22.0,@aws-cdk/aws-s3-notifications=0.22.0,@aws-cdk/aws-serverless=0.22.0,@aws-cdk/aws-sns=0.22.0,@aws-cdk/aws-sqs=0.22.0,@aws-cdk/cdk=0.22.0,@aws-cdk/cx-api=0.22.0,jsii-runtime=node.js/v11.12.0发布于 2020-05-06 15:35:46
你好,克里斯,我也遇到了同样的问题,下面是我是如何解决的:
PATH/||YOUR_ASSET_KEY
https://stackoverflow.com/questions/59553773
复制相似问题