AWSTemplateFormatVersion: "2010-09-09" Description: "Use AWS CodePipeline with third-party git repositories" Metadata: LICENSE: >- Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Parameters: SourceActionVersion: Description: The version of the custom source action to use. Type: String Default: '1' SourceActionProvider: Description: The provider name of the custom source action. Type: String Default: 'CustomSourceForGit' GitPullLambdaSubnet: Description: The subnet that the git pull Lambda function and CodeBuild will be deployed in. This should be a private subnet with a NAT gateway and your source control should be accessible from this subnet. Type: 'List' GitPullLambdaVpc: Description: The VPC you want to deploy the Git Pull lambda function and CodeBuild into. Type: 'AWS::EC2::VPC::Id' Default: '' LambdaCodeS3Bucket: Description: S3 bucket name for Lambda code for 3rd party git integration Type: String Default: aws-codepipeline-third-party-git-repositories-sample LambdaCodeS3Key: Description: s3 location of the Lambda code for 3rd party git integration Type: String Default: 'lambda/lambda.zip' Resources: GitPullCodeBuild: Type: AWS::CodeBuild::Project Properties: VpcConfig: VpcId: !Ref GitPullLambdaVpc SecurityGroupIds: [!Ref GitPullSecurityGroup] Subnets: !Ref GitPullLambdaSubnet Artifacts: Type: NO_ARTIFACTS Environment: Image: aws/codebuild/standard:2.0 Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL QueuedTimeoutInMinutes: 60 ServiceRole: !GetAtt CodeBuildServiceRole.Arn Source: BuildSpec: | version: 0.2 env: exported-variables: - GIT_COMMIT_ID - GIT_COMMIT_MSG phases: install: runtime-versions: python: 3.7 # commands: # - pip3 install boto3 build: commands: - echo "=======================Start-Deployment=============================" - echo "Setting temporary AWS CLI profile using CodePipeline job poll response" - PROFILE='temp-profile' - aws configure set aws_access_key_id $CodePipelineArtifactAccessKey --profile $PROFILE - aws configure set aws_secret_access_key $CodePipelineArtifactSecretAccessKey --profile $PROFILE - aws configure set aws_session_token $CodePipelineArtifactSessionToken --profile $PROFILE - echo "Getting the SSH Private Key" - aws secretsmanager get-secret-value --secret-id $SSHSecretKeyName --query 'SecretString' --output text >> ~/.ssh/id_rsa # - aws s3api get-object --bucket $KeyBucket --key $KeyObject ~/.ssh/id_rsa - ls ~/ - echo "Setting SSH config profile" - | cat > ~/.ssh/config <