I have the same problem. I spent literally days on this and I think there is something wrong with CouldFormatoin's AWS::CodeDeploy::DeploymentGroup
I have this yaml file in s3://my-backet-for-lambda-deployment/appspec.yaml
:
appspec.yaml
version: 0.0
Resources:
- my-lambda-app-MyLambdaApp-157EXYJT40C0U:
Type: AWS::Lambda::Function
Properties:
Name: arn:aws:lambda:us-east-1:292285124316:function:my-lambda-app-MyLambdaApp-157EXYJT40C0U
Alias: production
CurrentVersion: 8
TargetVersion: 9
The appspec.yaml
is correct, as I can manually specify it's location in S3 using the console and everything works. So I'm totally sure that the appspec.yaml
is not at fault here.
Problem
I use the following AWS::CodeDeploy::DeploymentGroup
MyDeploymentGroup:
Type: AWS::CodeDeploy::DeploymentGroup
Properties:
ApplicationName: !Ref MyCodeDeployApp
Deployment:
IgnoreApplicationStopFailures: false
Revision:
RevisionType: S3
S3Location:
Bucket: my-backet-for-lambda-deployment
Key: appspec.yaml
BundleType: YAML
DeploymentConfigName: CodeDeployDefault.LambdaAllAtOnce
DeploymentStyle:
DeploymentOption: WITH_TRAFFIC_CONTROL
DeploymentType: BLUE_GREEN
ServiceRoleArn: !ImportValue MyCodeDeployRoleArn
Stack creation of the above resource fails with Property Deployment cannot be specified.
Workaround
I couldn't found any solution to this purely based on CloudFormatoin. So what I did was to create DeploymentGroup
without defining Deployment
, and then use CLI or boto3 to start the deployment.
Resources:
MyCodeDeployApp:
Type: AWS::CodeDeploy::Application
Properties:
ComputePlatform: Lambda
# DeploymentGroup without Deployment property
MyDeploymentGroup:
Type: AWS::CodeDeploy::DeploymentGroup
Properties:
ApplicationName: !Ref MyCodeDeployApp
DeploymentConfigName: CodeDeployDefault.LambdaAllAtOnce
DeploymentStyle:
DeploymentOption: WITH_TRAFFIC_CONTROL
DeploymentType: BLUE_GREEN
ServiceRoleArn: !ImportValue MyCodeDeployRoleArn
Outputs:
CodeDeployAppName:
Value: !Ref MyCodeDeployApp
DeploymentGroupName:
Value: !Ref MyDeploymentGroup
Once the stack is create I can use bash to start a deployment:
aws deploy create-deployment \
--application-name ${deployment_app_name} \
--deployment-group-name ${deployment_group_name} \
--s3-location bucket=my-backet-for-lambda-deployment,bundleType=YAML,key=appspec.yaml
P.S.
MyCodeDeployRoleArn
role is also correct, so its not its fault either:
Resources:
MyCodeDeployServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: {Service: [codedeploy.amazonaws.com]}
Action: ['sts:AssumeRole']
Description: Role for deploying lambda
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda
Policies:
- PolicyName: MyS3GetObjectPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:Get*
- s3:List*
Resource: '*'
Outputs:
CodeDeployRoleArn:
Value: !GetAtt MyCodeDeployServiceRole.Arn
Export:
Name: MyCodeDeployRoleArn