diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 807ffc16..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": ".NET Core Launch (web)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite/bin/Debug/net6.0/PetSite.dll", - "args": [], - "cwd": "${workspaceFolder}/PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite", - "stopAtEntry": false, - // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser - "serverReadyAction": { - "action": "openExternally", - "pattern": "\\bNow listening on:\\s+(https?://\\S+)" - }, - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "sourceFileMap": { - "/Views": "${workspaceFolder}/Views" - } - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index e0c5a150..00000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite/PetSite.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite/PetSite.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "--project", - "${workspaceFolder}/PetAdoptions/cdk/pet_stack/resources/microservices/petsite/petsite/PetSite.csproj" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/.vscode/launch.json b/PetAdoptions/cdk/pet_stack/.vscode/launch.json index 35c64d45..d58296bb 100644 --- a/PetAdoptions/cdk/pet_stack/.vscode/launch.json +++ b/PetAdoptions/cdk/pet_stack/.vscode/launch.json @@ -11,7 +11,12 @@ "./node_modules/ts-node/register/transpile-only" ], // Entry point of your stack - "args": ["${workspaceFolder}/app/pet_stack.ts"] + "args": [ + "${workspaceFolder}/app/pet_stack.ts" + ], + "env": { + "CONFIG_PATH": "${workspaceFolder}/config.yaml" + } } ] } \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/app/pet_stack.ts b/PetAdoptions/cdk/pet_stack/app/pet_stack.ts index cbbd3db1..1e5000c5 100644 --- a/PetAdoptions/cdk/pet_stack/app/pet_stack.ts +++ b/PetAdoptions/cdk/pet_stack/app/pet_stack.ts @@ -1,26 +1,22 @@ #!/usr/bin/env node import 'source-map-support/register'; -import { Services } from '../lib/services'; -import { Applications } from '../lib/applications'; -//import { EKSPetsite } from '../lib/ekspetsite' import { App, Tags, Aspects } from 'aws-cdk-lib'; +import { CDKPipeline } from '../lib/pipeline'; //import { AwsSolutionsChecks } from 'cdk-nag'; -const stackName = "Services"; +const stackName = "OneObservabilityWorkshop"; const app = new App(); -const stack = new Services(app, stackName, { +const pipelineStack = new CDKPipeline(app, stackName+"Pipeline", { + sourceBucketName: process.env.SOURCE_BUCKET_NAME || "fake-bucket-wont-work", + branchName: process.env.GITHUB_BRANCH || "main", env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION -}}); + } +}); -const applications = new Applications(app, "Applications", { - env: { - account: process.env.CDK_DEFAULT_ACCOUNT, - region: process.env.CDK_DEFAULT_REGION -}}); Tags.of(app).add("Workshop","true") //Aspects.of(stack).add(new AwsSolutionsChecks({verbose: true})); diff --git a/PetAdoptions/cdk/pet_stack/config.yaml b/PetAdoptions/cdk/pet_stack/config.yaml new file mode 100644 index 00000000..0caadef1 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/config.yaml @@ -0,0 +1 @@ +createXRayGroup: true \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/applicationsStage.ts b/PetAdoptions/cdk/pet_stack/lib/applicationsStage.ts new file mode 100644 index 00000000..90181653 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/applicationsStage.ts @@ -0,0 +1,17 @@ + +import { Stage, StageProps } from "aws-cdk-lib"; +import { Construct } from "constructs"; +import { Applications } from "./stacks/applications"; + +export class ApplicationsStage extends Stage { + constructor(scope: Construct, id: string, props: StageProps) { + super(scope, id, props); + + const stackName = "Applications"; + const stack = new Applications(this, stackName, { + env: { + account: props.env?.account, + region: props.env?.region + }}); + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/common/config.ts b/PetAdoptions/cdk/pet_stack/lib/common/config.ts new file mode 100644 index 00000000..01a0cc6e --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/common/config.ts @@ -0,0 +1,32 @@ +import * as fs from 'fs'; +import path = require('path'); +import * as yaml from 'js-yaml'; +import { log } from 'console'; +import { Construct } from 'constructs'; + +export interface WorkshopConfig +{ + readonly createXRayGroup : boolean; +} + +export function getConfig(app: Construct) : WorkshopConfig { + + // Default configuration + let config = { + createXRayGroup: false + }; + if (process.env.CONFIG_PATH) { + let configPath = process.env.CONFIG_PATH; + log(`Using config file: ${configPath}`); + /// Check if the file exists and is not empty + if (!fs.existsSync(configPath)) { + throw new Error(`Config file ${configPath} does not exist`); + } + /// Check if configPath exists. If it exists read the content of the file as YAML and convert the result into an object using WorkshopConfig interface + let configContent = fs.readFileSync(configPath, 'utf8'); + config = yaml.load(configContent) as WorkshopConfig; + } + + + return config; +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/constructs/imageBuiltStep.ts b/PetAdoptions/cdk/pet_stack/lib/constructs/imageBuiltStep.ts new file mode 100644 index 00000000..0d330f2a --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/constructs/imageBuiltStep.ts @@ -0,0 +1,50 @@ +import { PolicyStatement } from "aws-cdk-lib/aws-iam"; +import { CodeBuildStep, CodePipelineSource } from "aws-cdk-lib/pipelines"; + +export interface ImageBuildStepProps { + repositoryName: string; + repositoryUri: string; + source: CodePipelineSource; + account: string; + region: string; + branchName: string; + +} + +export class ImageBuildStep extends CodeBuildStep { + constructor(name: string, props: ImageBuildStepProps) { + super(name, { + commands: [ + 'nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &', + 'timeout 15 sh -c "until docker info; do echo .; sleep 1; done"', + 'cd ${BASE_PATH}', + 'aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com', + 'docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .', + 'docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG', + 'docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG' + ], + rolePolicyStatements: [ + new PolicyStatement({ + actions: [ + 'ecr:*', + ], + resources: ['*'], + }), + ], + input: props.source, + buildEnvironment: { + privileged: true + }, + env: { + 'AWS_ACCOUNT_ID': props.account, + 'AWS_DEFAULT_REGION': props.region, + 'IMAGE_TAG': "latest", + 'ECR_REPOSITORY_URL': props.repositoryUri, + 'IMAGE_REPO_NAME': props.repositoryName, + 'BASE_PATH': `one-observability-demo-${props.branchName}/PetAdoptions/${props.repositoryName}` + } + }); + + this.consumedStackOutputs.push() + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/constructs/network.ts b/PetAdoptions/cdk/pet_stack/lib/constructs/network.ts new file mode 100644 index 00000000..37b543d3 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/constructs/network.ts @@ -0,0 +1,69 @@ +import { Construct } from "constructs"; +import * as ec2 from 'aws-cdk-lib/aws-ec2'; +import * as logs from 'aws-cdk-lib/aws-logs'; +import * as iam from 'aws-cdk-lib/aws-iam'; + +export interface WorkshopNetworkProps { + name: string; + cidrRange: string; +} + +export class WorkshopNetwork extends Construct { + public readonly vpc : ec2.Vpc; + constructor(scope: Construct, id: string, props: WorkshopNetworkProps) { + super(scope, id); + + // Create a VPC with public and private subnets + // The VPC where all the microservices will be deployed into + this.vpc = new ec2.Vpc(this, 'VPC-' + props.name, { + ipAddresses: ec2.IpAddresses.cidr(props.cidrRange), + natGateways: 1, + maxAzs: 2 + }); + + const flowLogGroup = new logs.LogGroup(this, 'FlowLogGroup', { + logGroupName: '/aws/vpcflowlogs/' + this.vpc.vpcId, + retention: logs.RetentionDays.ONE_WEEK + }); + + const role = new iam.Role(this, 'VPCFlowLogRole', { + assumedBy: new iam.ServicePrincipal('vpc-flow-logs.amazonaws.com') + }); + + const flowLog = new ec2.FlowLog(this, 'VPCFlowLog', { + destination: ec2.FlowLogDestination.toCloudWatchLogs(flowLogGroup, role), + resourceType: ec2.FlowLogResourceType.fromVpc(this.vpc), + logFormat: [ + ec2.LogFormat.ACCOUNT_ID, + ec2.LogFormat.ACTION, + ec2.LogFormat.AZ_ID, + ec2.LogFormat.BYTES, + ec2.LogFormat.DST_ADDR, + ec2.LogFormat.DST_PORT, + ec2.LogFormat.END_TIMESTAMP, + ec2.LogFormat.FLOW_DIRECTION, + ec2.LogFormat.INSTANCE_ID, + ec2.LogFormat.INTERFACE_ID, + ec2.LogFormat.LOG_STATUS, + ec2.LogFormat.PACKETS, + ec2.LogFormat.PKT_DST_AWS_SERVICE, + ec2.LogFormat.PKT_DST_ADDR, + ec2.LogFormat.PKT_SRC_AWS_SERVICE, + ec2.LogFormat.PKT_SRC_ADDR, + ec2.LogFormat.PROTOCOL, + ec2.LogFormat.REGION, + ec2.LogFormat.SRC_ADDR, + ec2.LogFormat.SRC_PORT, + ec2.LogFormat.START_TIMESTAMP, + ec2.LogFormat.SUBLOCATION_ID, + ec2.LogFormat.SUBLOCATION_TYPE, + ec2.LogFormat.SUBNET_ID, + ec2.LogFormat.TCP_FLAGS, + ec2.LogFormat.TRAFFIC_PATH, + ec2.LogFormat.TRAFFIC_TYPE, + ec2.LogFormat.VERSION, + ec2.LogFormat.VPC_ID + ] + }); + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/constructs/repository.ts b/PetAdoptions/cdk/pet_stack/lib/constructs/repository.ts new file mode 100644 index 00000000..414b5b0b --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/constructs/repository.ts @@ -0,0 +1,36 @@ +import { RemovalPolicy, Stack } from 'aws-cdk-lib'; +import { Construct } from "constructs"; +import * as ecr from "aws-cdk-lib/aws-ecr"; +import * as iam from "aws-cdk-lib/aws-iam"; +import { NagSuppressions } from 'cdk-nag'; +import { CodeBuildStep } from 'aws-cdk-lib/pipelines'; + +export interface RepositoryProps { + name: string; + enableScanOnPush: boolean; + initialCodePath: string; +} + + +export class Repository extends Construct { + public readonly imageRepo: ecr.Repository + public readonly codeBuildStep: CodeBuildStep; + + constructor(scope: Construct, id: string, props: RepositoryProps) { + super(scope, id); + + this.imageRepo = new ecr.Repository(scope, props.name + "ImageRepo", { + repositoryName: props.name, + imageScanOnPush: props.enableScanOnPush, + imageTagMutability: ecr.TagMutability.MUTABLE, // Set to Mutable to allow the Pipeline to run multiple times. An alternative solution can be used to delete the latest before pushing the new build. + removalPolicy: RemovalPolicy.DESTROY, + encryption: ecr.RepositoryEncryption.AES_256, + autoDeleteImages: true + }); + + } + + public getECRUri() { + return this.imageRepo.repositoryUri; + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/imageBuilderStage.ts b/PetAdoptions/cdk/pet_stack/lib/imageBuilderStage.ts new file mode 100644 index 00000000..0462aac2 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/imageBuilderStage.ts @@ -0,0 +1,20 @@ +import { Stage, StageProps } from "aws-cdk-lib"; +import { Construct } from "constructs"; +import { ImageBuilderStack } from "./stacks/imageBuilder"; + +export class ImageBuilderStage extends Stage { + public readonly repoList = new Map(); + constructor(scope: Construct, id: string, props: StageProps) { + super(scope, id, props); + + const stackName = "ImageBuilder"; + const coreStack = new ImageBuilderStack(this, stackName, { + env: { + account: props.env?.account, + region: props.env?.region + }, + }); + + this.repoList = coreStack.repoList; + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/modules/core/cloud9.ts b/PetAdoptions/cdk/pet_stack/lib/modules/core/cloud9.ts deleted file mode 100644 index bef74833..00000000 --- a/PetAdoptions/cdk/pet_stack/lib/modules/core/cloud9.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Construct } from "constructs"; -import * as cloudformation_include from "aws-cdk-lib/cloudformation-include"; -import { CfnRole } from "aws-cdk-lib/aws-iam"; - -export interface Cloud9EnvironmentProps { - name?: string; - vpcId: string; - subnetId: string; - templateFile: string; - cloud9OwnerArn?: string; -} - -export class Cloud9Environment extends Construct { - public readonly c9Role: CfnRole; - constructor(scope: Construct, id: string, props: Cloud9EnvironmentProps) { - super(scope, id); - - const template = new cloudformation_include.CfnInclude(this, 'Cloud9Template', { - templateFile: props.templateFile, - parameters: { - 'CreateVPC': false, - 'Cloud9VPC': props.vpcId, - 'Cloud9Subnet': props.subnetId - }, - preserveLogicalIds: false - }); - - if (props.name) { - template.getParameter("EnvironmentName").default = props.name; - } - - if (props.cloud9OwnerArn) { - template.getParameter("Cloud9OwnerRole").default = props.cloud9OwnerArn.valueOf(); - } - - this.c9Role = template.getResource("C9Role") as CfnRole; - - } -} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/pipeline.ts b/PetAdoptions/cdk/pet_stack/lib/pipeline.ts new file mode 100644 index 00000000..2f8fde95 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/pipeline.ts @@ -0,0 +1,92 @@ +import * as cdk from 'aws-cdk-lib'; +import { Construct } from 'constructs'; +import { CodeBuildStep, CodePipeline, CodePipelineSource } from 'aws-cdk-lib/pipelines'; +import { Bucket } from 'aws-cdk-lib/aws-s3'; +import { PolicyStatement } from 'aws-cdk-lib/aws-iam'; +import { ImageBuilderStage } from './imageBuilderStage'; +import { ImageBuildStep } from './constructs/imageBuiltStep'; +import { ServiceStage } from './servicesStage'; +import { ApplicationsStage } from './applicationsStage'; + +export interface CDKPipelineProps extends cdk.StackProps { + sourceBucketName: string; + branchName: string; +}; + +export class CDKPipeline extends cdk.Stack { + constructor(scope: Construct, id: string, props: CDKPipelineProps) { + super(scope, id, props); + + const sourceBucket = Bucket.fromBucketName(this, 'SourceBucket', props.sourceBucketName); + + const source = CodePipelineSource.s3(sourceBucket,'Repository.zip'); + + const synthStep = new CodeBuildStep('SynthStep', { + input: source, + env: { + 'SOURCE_BUCKET_NAME':props.sourceBucketName, + 'GITHUB_BRANCH':props.branchName + }, + commands: [ + `cd one-observability-demo-${props.branchName}/PetAdoptions/cdk/pet_stack`, + 'npm install', + 'npm ci', + 'npm run build', + 'npx cdk synth'], + rolePolicyStatements: [ + new PolicyStatement({ + actions: [ + 'logs:CreateLogGroup', + 'logs:CreateLogStream', + 'logs:PutLogEvents', + 'secretsmanager:*', + 'lambda:*', + 's3:*', + 'ec2:DescribeAvailabilityZones', + ], + resources: ['*'], + }), + ], + primaryOutputDirectory: `one-observability-demo-${props.branchName}/PetAdoptions/cdk/pet_stack/cdk.out` + }); + + const pipeline = new CodePipeline(this, 'CodePipeline', { + pipelineName: 'OneObservabilityWorkshopPipeline', + synth: synthStep + }); + + const coreStage = new ImageBuilderStage(scope, "Repositories", {}); + pipeline.addStage(coreStage); + + const imageBuildSteps = new Array(); + + coreStage.repoList.forEach((value, key) => { + imageBuildSteps.push(new ImageBuildStep(key, { + repositoryName: key, + repositoryUri: value, + source: source, + account: this.account, + region: this.region, + branchName: props.branchName, + })); + }); + + const imageWave = pipeline.addWave("ImageBuildWave", { + post: imageBuildSteps, + }); + + const serviceStage = pipeline.addStage(new ServiceStage(scope, "Services", { + env: { + account: process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_DEFAULT_REGION + } + })); + + const applicationStage = pipeline.addStage(new ApplicationsStage(scope, "Applications", { + env: { + account: process.env.CDK_DEFAULT_ACCOUNT, + region: process.env.CDK_DEFAULT_REGION + } + })); + } +}; \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/services/list-adoptions-service.ts b/PetAdoptions/cdk/pet_stack/lib/services/list-adoptions-service.ts index 4574cb3b..b4bcbffc 100644 --- a/PetAdoptions/cdk/pet_stack/lib/services/list-adoptions-service.ts +++ b/PetAdoptions/cdk/pet_stack/lib/services/list-adoptions-service.ts @@ -18,7 +18,7 @@ export class ListAdoptionsService extends EcsService { } containerImageFromRepository(repositoryURI: string) : ecs.ContainerImage { - return ecs.ContainerImage.fromRegistry(`${repositoryURI}/pet-listadoptions:latest`) + return ecs.ContainerImage.fromRegistry(`${repositoryURI}/petlistadoptions-go:latest`) } createContainerImage() : ecs.ContainerImage { diff --git a/PetAdoptions/cdk/pet_stack/lib/services/pay-for-adoption-service.ts b/PetAdoptions/cdk/pet_stack/lib/services/pay-for-adoption-service.ts index dd78691f..870dee4d 100644 --- a/PetAdoptions/cdk/pet_stack/lib/services/pay-for-adoption-service.ts +++ b/PetAdoptions/cdk/pet_stack/lib/services/pay-for-adoption-service.ts @@ -17,7 +17,7 @@ export class PayForAdoptionService extends EcsService { } containerImageFromRepository(repositoryURI: string) : ecs.ContainerImage { - return ecs.ContainerImage.fromRegistry(`${repositoryURI}/pet-payforadoption:latest`) + return ecs.ContainerImage.fromRegistry(`${repositoryURI}/payforadoption-go:latest`) } createContainerImage() : ecs.ContainerImage { diff --git a/PetAdoptions/cdk/pet_stack/lib/services/search-service.ts b/PetAdoptions/cdk/pet_stack/lib/services/search-service.ts index 03445850..fad5dc5f 100644 --- a/PetAdoptions/cdk/pet_stack/lib/services/search-service.ts +++ b/PetAdoptions/cdk/pet_stack/lib/services/search-service.ts @@ -14,7 +14,7 @@ export class SearchService extends EcsService { } containerImageFromRepository(repositoryURI: string) : ecs.ContainerImage { - return ecs.ContainerImage.fromRegistry(`${repositoryURI}/pet-search-java:latest`) + return ecs.ContainerImage.fromRegistry(`${repositoryURI}/petsearch-java:latest`) } createContainerImage() : ecs.ContainerImage { diff --git a/PetAdoptions/cdk/pet_stack/lib/services/traffic-generator-service.ts b/PetAdoptions/cdk/pet_stack/lib/services/traffic-generator-service.ts index 4b871dd4..8c2bb3ad 100644 --- a/PetAdoptions/cdk/pet_stack/lib/services/traffic-generator-service.ts +++ b/PetAdoptions/cdk/pet_stack/lib/services/traffic-generator-service.ts @@ -10,12 +10,12 @@ export class TrafficGeneratorService extends EcsService { } containerImageFromRepository(repositoryURI: string) : ecs.ContainerImage { - return ecs.ContainerImage.fromRegistry(`${repositoryURI}/pet-trafficgenerator:latest`) + return ecs.ContainerImage.fromRegistry(`${repositoryURI}/trafficgenerator:latest`) } createContainerImage() : ecs.ContainerImage { return ecs.ContainerImage.fromDockerImageAsset(new DockerImageAsset(this, "traffic-generator", { - directory: "./resources/microservices/trafficgenerator/trafficgenerator" + directory: "./resources/microservices/trafficgenerator" })) } } diff --git a/PetAdoptions/cdk/pet_stack/lib/servicesStage.ts b/PetAdoptions/cdk/pet_stack/lib/servicesStage.ts new file mode 100644 index 00000000..de1c3449 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/servicesStage.ts @@ -0,0 +1,16 @@ +import { Stage, StageProps } from "aws-cdk-lib"; +import { Construct } from "constructs"; +import { Services } from "./stacks/services"; + +export class ServiceStage extends Stage { + constructor(scope: Construct, id: string, props: StageProps) { + super(scope, id, props); + + const stackName = "Services"; + const stack = new Services(this, stackName, { + env: { + account: props.env?.account, + region: props.env?.region + }}); + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/applications.ts b/PetAdoptions/cdk/pet_stack/lib/stacks/applications.ts similarity index 87% rename from PetAdoptions/cdk/pet_stack/lib/applications.ts rename to PetAdoptions/cdk/pet_stack/lib/stacks/applications.ts index 6736c1f5..d606982c 100644 --- a/PetAdoptions/cdk/pet_stack/lib/applications.ts +++ b/PetAdoptions/cdk/pet_stack/lib/stacks/applications.ts @@ -7,8 +7,8 @@ import * as yaml from 'js-yaml'; import { Stack, StackProps, CfnJson, Fn, CfnOutput } from 'aws-cdk-lib'; import { readFileSync } from 'fs'; import { Construct } from 'constructs' -import { ContainerImageBuilderProps, ContainerImageBuilder } from './common/container-image-builder' -import { PetAdoptionsHistory } from './applications/pet-adoptions-history-application' +import { ContainerImageBuilderProps, ContainerImageBuilder } from '../common/container-image-builder' +import { PetAdoptionsHistory } from '../applications/pet-adoptions-history-application' export class Applications extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { @@ -74,16 +74,13 @@ export class Applications extends Stack { petstoreserviceaccount.addToPrincipalPolicy(startStepFnExecutionPolicy); - const petsiteAsset = new DockerImageAsset(this, 'petsiteAsset', { - directory: "./resources/microservices/petsite/petsite/" - }); - + const repositoryURI = `${this.account}.dkr.ecr.${this.region}.amazonaws.com`; var manifest = readFileSync("./resources/k8s_petsite/deployment.yaml","utf8"); var deploymentYaml = yaml.loadAll(manifest) as Record[]; deploymentYaml[0].metadata.annotations["eks.amazonaws.com/role-arn"] = new CfnJson(this, "deployment_Role", { value : `${petstoreserviceaccount.roleArn}` }); - deploymentYaml[2].spec.template.spec.containers[0].image = new CfnJson(this, "deployment_Image", { value : `${petsiteAsset.imageUri}` }); + deploymentYaml[2].spec.template.spec.containers[0].image = new CfnJson(this, "deployment_Image", { value : `${repositoryURI + "/petsite:latest"}` }); deploymentYaml[3].spec.targetGroupARN = new CfnJson(this,"targetgroupArn", { value: `${targetGroupArn}`}) const deploymentManifest = new eks.KubernetesManifest(this,"petsitedeployment",{ @@ -91,13 +88,8 @@ export class Applications extends Stack { manifest: deploymentYaml }); - // PetAdoptionsHistory application definitions----------------------------------------------------------------------- - const petAdoptionsHistoryContainerImage = new ContainerImageBuilder(this, 'pet-adoptions-history-container-image', { - repositoryName: "pet-adoptions-history", - dockerImageAssetDirectory: "./resources/microservices/petadoptionshistory-py", - }); new ssm.StringParameter(this,"putPetAdoptionHistoryRepositoryName",{ - stringValue: petAdoptionsHistoryContainerImage.repositoryUri, + stringValue: `${repositoryURI}/petadoptionshistory-py`, parameterName: '/petstore/pethistoryrepositoryuri' }); @@ -108,7 +100,7 @@ export class Applications extends Stack { otelConfigMapPath: "./resources/microservices/petadoptionshistory-py/otel-collector-config.yaml", rdsSecretArn: rdsSecretArn, region: region, - imageUri: petAdoptionsHistoryContainerImage.imageUri, + imageUri: `${repositoryURI}/petadoptionshistory-py`, targetGroupArn: petHistoryTargetGroupArn }); @@ -117,7 +109,7 @@ export class Applications extends Stack { }))); this.createOuputs(new Map(Object.entries({ - 'PetSiteECRImageURL': petsiteAsset.imageUri, + 'PetSiteECRImageURL': `${repositoryURI + "/petsite:latest"}`, 'PetStoreServiceAccountArn': petstoreserviceaccount.roleArn, }))); // Creating AWS Resource Group for all the resources of stack. diff --git a/PetAdoptions/cdk/pet_stack/lib/stacks/imageBuilder.ts b/PetAdoptions/cdk/pet_stack/lib/stacks/imageBuilder.ts new file mode 100644 index 00000000..5e01f8e3 --- /dev/null +++ b/PetAdoptions/cdk/pet_stack/lib/stacks/imageBuilder.ts @@ -0,0 +1,49 @@ +import { Aspects, CfnOutput, Stack, StackProps, Tags } from 'aws-cdk-lib'; +import { AwsSolutionsChecks, NagSuppressions } from "cdk-nag"; +import { Construct } from 'constructs'; +import * as fs from 'fs'; +import path = require('path'); +import { Repository } from '../constructs/repository'; + + +export class ImageBuilderStack extends Stack { + public readonly repoList = new Map(); + constructor(scope: Construct, id: string, props: StackProps) { + super(scope, id, props); + + // Suppressions for the ImageBuilder Stack + NagSuppressions.addStackSuppressions(this, [ + { id: "AwsSolutions-IAM4", reason: "Stack level suppression, managed policies are aceptable in this workshop."} + ]) + + const repoFolders = __dirname + "/../../resources/microservices"; + const repositories = fs.readdirSync(repoFolders); + const basePath = path.resolve(repoFolders); + + repositories.forEach(container => { + + const repo = new Repository(this, container, { + name: container, + enableScanOnPush: true, + initialCodePath: basePath + "/" + container, + }); + + + this.repoList.set(container, repo.getECRUri()); + }); + + this.repoList.forEach((value, key) => { + new CfnOutput(this, key + "Uri", { value: value }) + }) + + Tags.of(this).add("Workshop","true") + Tags.of(this).add("ModularVersioning","true") + Aspects.of(this).add(new AwsSolutionsChecks({verbose: true})); + + function createOuputs(scope: Construct ,params: Map) { + params.forEach((value, key) => { + new CfnOutput(scope, key, { value: value }) + }); + } + } +} \ No newline at end of file diff --git a/PetAdoptions/cdk/pet_stack/lib/services.ts b/PetAdoptions/cdk/pet_stack/lib/stacks/services.ts similarity index 96% rename from PetAdoptions/cdk/pet_stack/lib/services.ts rename to PetAdoptions/cdk/pet_stack/lib/stacks/services.ts index b220f602..a7f3cc62 100644 --- a/PetAdoptions/cdk/pet_stack/lib/services.ts +++ b/PetAdoptions/cdk/pet_stack/lib/stacks/services.ts @@ -23,19 +23,20 @@ import * as applicationinsights from 'aws-cdk-lib/aws-applicationinsights'; import * as resourcegroups from 'aws-cdk-lib/aws-resourcegroups'; import { Construct } from 'constructs' -import { PayForAdoptionService } from './services/pay-for-adoption-service' -import { ListAdoptionsService } from './services/list-adoptions-service' -import { SearchService } from './services/search-service' -import { TrafficGeneratorService } from './services/traffic-generator-service' -import { StatusUpdaterService } from './services/status-updater-service' -import { PetAdoptionsStepFn } from './services/stepfn' +import { PayForAdoptionService } from '../services/pay-for-adoption-service' +import { ListAdoptionsService } from '../services/list-adoptions-service' +import { SearchService } from '../services/search-service' +import { TrafficGeneratorService } from '../services/traffic-generator-service' +import { StatusUpdaterService } from '../services/status-updater-service' +import { PetAdoptionsStepFn } from '../services/stepfn' import { KubernetesVersion } from 'aws-cdk-lib/aws-eks'; import { CfnJson, RemovalPolicy, Fn, Duration, Stack, StackProps, CfnOutput } from 'aws-cdk-lib'; import { readFileSync } from 'fs'; import 'ts-replace-all' import { TreatMissingData, ComparisonOperator } from 'aws-cdk-lib/aws-cloudwatch'; import { KubectlLayer } from 'aws-cdk-lib/lambda-layer-kubectl'; -import { Cloud9Environment } from './modules/core/cloud9'; +import { getConfig } from '../common/config'; +import { CfnGroup } from 'aws-cdk-lib/aws-xray'; export class Services extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { @@ -43,6 +44,17 @@ export class Services extends Stack { const stackName = id; + // Retrieve the configuration from the context + const config = getConfig(scope); + + if (config.createXRayGroup) { + const xrayGroup = new CfnGroup(this, 'xrayGroup', { + groupName: 'Higherlatency', + filterExpression: "responsetime > 2", + }) + } + + // Create SQS resource to send Pet adoption messages to const sqsQueue = new sqs.Queue(this, 'sqs_petadoption', { visibilityTimeout: Duration.seconds(300) @@ -166,7 +178,7 @@ export class Services extends Stack { resources: ['*'] }); - const repositoryURI = "public.ecr.aws/one-observability-workshop"; + const repositoryURI = `${this.account}.dkr.ecr.${this.region}.amazonaws.com`; const stack = Stack.of(this); const region = stack.region; @@ -189,7 +201,7 @@ export class Services extends Stack { memoryLimitMiB: 2048, healthCheck: '/health/status', // build locally - //repositoryURI: repositoryURI, + repositoryURI: repositoryURI, database: auroraCluster, desiredTaskCount : 2, region: region, @@ -212,7 +224,7 @@ export class Services extends Stack { healthCheck: '/health/status', instrumentation: 'otel', // build locally - //repositoryURI: repositoryURI, + repositoryURI: repositoryURI, database: auroraCluster, desiredTaskCount: 2, region: region, @@ -230,7 +242,7 @@ export class Services extends Stack { logGroupName: "/ecs/PetSearch", cpu: 1024, memoryLimitMiB: 2048, - //repositoryURI: repositoryURI, + repositoryURI: repositoryURI, healthCheck: '/health/status', desiredTaskCount: 2, instrumentation: 'otel', @@ -246,7 +258,7 @@ export class Services extends Stack { cpu: 256, memoryLimitMiB: 512, instrumentation: 'none', - //repositoryURI: repositoryURI, + repositoryURI: repositoryURI, desiredTaskCount: 1, region: region, securityGroup: ecsServicesSecurityGroup @@ -534,7 +546,7 @@ export class Services extends Stack { customWidgetLambdaRole.addToPrincipalPolicy(customWidgetResourceControllerPolicy); var petsiteApplicationResourceController = new lambda.Function(this, 'petsite-application-resource-controler', { - code: lambda.Code.fromAsset(path.join(__dirname, '/../resources/resource-controller-widget')), + code: lambda.Code.fromAsset(path.join(__dirname, '/../../resources/resource-controller-widget')), handler: 'petsite-application-resource-controler.lambda_handler', memorySize: 128, runtime: lambda.Runtime.PYTHON_3_9, @@ -546,7 +558,7 @@ export class Services extends Stack { ecsPetListAdoptionCluster.clusterArn + "," + ecsPetSearchCluster.clusterArn); var customWidgetFunction = new lambda.Function(this, 'cloudwatch-custom-widget', { - code: lambda.Code.fromAsset(path.join(__dirname, '/../resources/resource-controller-widget')), + code: lambda.Code.fromAsset(path.join(__dirname, '/../../resources/resource-controller-widget')), handler: 'cloudwatch-custom-widget.lambda_handler', memorySize: 128, runtime: lambda.Runtime.PYTHON_3_9, @@ -594,7 +606,7 @@ export class Services extends Stack { }); var dynamodbQueryFunction = new lambda.Function(this, 'dynamodb-query-function', { - code: lambda.Code.fromAsset(path.join(__dirname, '/../resources/application-insights')), + code: lambda.Code.fromAsset(path.join(__dirname, '/../../resources/application-insights')), handler: 'dynamodb-query-function.lambda_handler', memorySize: 128, runtime: lambda.Runtime.PYTHON_3_9, diff --git a/PetAdoptions/payforadoption-go/Dockerfile b/PetAdoptions/payforadoption-go/Dockerfile index 73075e46..cc375ec4 100644 --- a/PetAdoptions/payforadoption-go/Dockerfile +++ b/PetAdoptions/payforadoption-go/Dockerfile @@ -1,11 +1,11 @@ -FROM golang:1.20 as builder +FROM public.ecr.aws/docker/library/golang:1.20 as builder WORKDIR /go/src/app COPY . . ENV GOPROXY=https://goproxy.io,direct RUN go get . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . -FROM alpine:latest +FROM public.ecr.aws/docker/library/alpine:latest WORKDIR /app RUN apk --no-cache add ca-certificates COPY --from=builder /go/src/app/app . diff --git a/PetAdoptions/petadoptionshistory-py/Dockerfile b/PetAdoptions/petadoptionshistory-py/Dockerfile index 8819c2ef..b9c39595 100644 --- a/PetAdoptions/petadoptionshistory-py/Dockerfile +++ b/PetAdoptions/petadoptionshistory-py/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM python:3.8 +FROM public.ecr.aws/docker/library/python:3.8 WORKDIR /app diff --git a/PetAdoptions/petfood-metric/Dockerfile b/PetAdoptions/petfood-metric/Dockerfile deleted file mode 100644 index 7f9ff77a..00000000 --- a/PetAdoptions/petfood-metric/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# syntax=docker/dockerfile:1 - -FROM python:3.8-slim-buster - -WORKDIR /app - -COPY requirements.txt requirements.txt -RUN pip3 install -r requirements.txt - -COPY . . -ENV FLASK_APP=petfood-metric - -CMD [ "python3", "-m" , "gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "--capture-output", "petfood-metric:app"] diff --git a/PetAdoptions/petfood-metric/deployment.yaml b/PetAdoptions/petfood-metric/deployment.yaml deleted file mode 100644 index 9a9a837b..00000000 --- a/PetAdoptions/petfood-metric/deployment.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: petfood-metric - labels: - app: petfood-metric -spec: - replicas: 2 - selector: - matchLabels: - app: petfood-metric - template: - metadata: - labels: - app: petfood-metric - spec: - containers: - - env: - - name: AWS_XRAY_DAEMON_ADDRESS - value: xray-service:2000 - - name: AWS_DEFAULT_REGION - value: DEPLOYMENTREGION - name: petfood-metric - image: DEPLOYMENTACCOUNT.dkr.ecr.DEPLOYMENTREGION.amazonaws.com/petfood-metric:1 - ports: - - containerPort: 5000 -# livenessProbe: -# httpGet: -# path: /status -# port: 5000 -# initialDelaySeconds: 3 -# periodSeconds: 3 - ---- -apiVersion: v1 -kind: Service -metadata: - name: petfood-metric - labels: - app: petfood-metric -spec: - ports: - - port: 80 - protocol: TCP - targetPort: 5000 - selector: - app: petfood-metric diff --git a/PetAdoptions/petfood-metric/petfood-metric.py b/PetAdoptions/petfood-metric/petfood-metric.py deleted file mode 100644 index 03933e1b..00000000 --- a/PetAdoptions/petfood-metric/petfood-metric.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python # pylint: disable=C0103 - -"""Simple microservice to show Evidently features""" - -import json -import logging -import os -import time -import boto3 -from aws_xray_sdk.ext.flask.middleware import XRayMiddleware -from aws_xray_sdk.core import patch_all, xray_recorder -from flask import Flask, request - - -app = Flask(__name__) -xray_recorder.configure(service='petfood-metric') -patch_all() -XRayMiddleware(app, xray_recorder) - - -class StructuredMessage: # pylint: disable=R0903 - """Use to make JSON formatted logging work well for CWL""" - def __init__(self, message, /, **kwargs): - self.message = message - self.kwargs = kwargs - - def __str__(self): - return f'{self.message} - {self.kwargs}' - - -_ = StructuredMessage -logging.basicConfig(level=os.getenv('LOG_LEVEL', 20), format='%(message)s') -logger = logging.getLogger() - - -class EvidentlyProject: - """Base for all Evidently interactions""" - - def __init__(self): - self.client = boto3.client('evidently') - self.project = os.getenv('EVIDENTLY_PROJECT', 'petfood') - - def project_exists(self): - """Returns False if the project does not currently exist""" - xray_recorder.begin_subsegment('evidently project_exists') - try: - response = self.client.get_project(project=self.project) - logger.info(_('checking for evidently project', response=response)) - xray_recorder.end_subsegment() - return True - except self.client.exceptions.ResourceNotFoundException: - logger.warning(_('evidently project not found')) - xray_recorder.end_subsegment() - return None - - def put_metric(self, entity_id, value): - """Puts metric into Evidently""" - data = json.dumps({ - 'userDetails': {'entityId': entity_id}, - 'details': {'donation': value} - }) - response = self.client.put_project_events( - events=[{'timestamp': time.time(), - 'data': data, - 'type': 'aws.evidently.custom'}], - project=self.project - ) - logger.warning(_('response to put_metric call', response=response)) - - -@app.route('/metric//') -def root_path(entity_id, value): - """Base URL for our handler""" - logger.info(_('raw request headers', headers=request.headers)) - xray_recorder.begin_segment('petfood-metric') - evidently = EvidentlyProject() - project = evidently.project_exists() - if not project: - return json.dumps({'statusCode': 404, 'body': 'evidently project not found'}) - evidently.put_metric(str(entity_id), float(value)) - # xray_recorder.end_segment() - return json.dumps('ok') - - -@app.route('/status') -def status_path(): - logger.info(_('raw request headers', headers=request.headers)) - """Used for health checks""" - return json.dumps({'statusCode': 200, 'body': 'ok'}) diff --git a/PetAdoptions/petfood-metric/policy.json b/PetAdoptions/petfood-metric/policy.json deleted file mode 100644 index 05119e76..00000000 --- a/PetAdoptions/petfood-metric/policy.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "Version": "2012-10-17", - "Statement": [ - { - "Sid": "VisualEditor0", - "Effect": "Allow", - "Action": [ - "evidently:GetProject", - "evidently:PutProjectEvents", - "evidently:EvaluateFeature" - ], - "Resource": "*" - } - ] -} diff --git a/PetAdoptions/petfood-metric/requirements.txt b/PetAdoptions/petfood-metric/requirements.txt deleted file mode 100644 index d822d977..00000000 --- a/PetAdoptions/petfood-metric/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -aws-xray-sdk==2.9.0 -Flask==2.0.2 -boto3==1.20.21 -gunicorn==20.1.0 diff --git a/PetAdoptions/petfood/Dockerfile b/PetAdoptions/petfood/Dockerfile deleted file mode 100644 index 2e4e52eb..00000000 --- a/PetAdoptions/petfood/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# syntax=docker/dockerfile:1 - -FROM python:3.8-slim-buster - -WORKDIR /app - -COPY requirements.txt requirements.txt -RUN pip3 install -r requirements.txt - -COPY . . -ENV FLASK_APP=petfood - -CMD [ "python3", "-m" , "gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "--capture-output", "petfood:app"] diff --git a/PetAdoptions/petfood/activate.sh b/PetAdoptions/petfood/activate.sh deleted file mode 100755 index f667124c..00000000 --- a/PetAdoptions/petfood/activate.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - - -deploy () { - cd $HOME/environment/workshopfiles/one-observability-demo/PetAdoptions/${service} - echo In directory `pwd` - echo "Startng deployment of ${service}" - - if [ ! "`aws ecr describe-repositories --repository-names ${service}`" ] ; then - echo ${service} repository not found, creating... - aws ecr create-repository --repository-name ${service} - else - echo ${service} repository found, skipping creation - fi - - aws ecr get-login-password | docker login --username AWS --password-stdin `aws ecr describe-repositories --repository-names ${service} | jq .repositories[0].repositoryUri | sed "s/\"//g"` - - docker build -t ${service}:1 . - docker tag ${service}:1 `aws ecr describe-repositories --repository-names ${service} | jq .repositories[0].repositoryUri | sed "s/\"//g"`:1 - docker push `aws ecr describe-repositories --repository-names ${service} | jq .repositories[0].repositoryUri | sed "s/\"//g"`:1 - - sed -i "s/DEPLOYMENTACCOUNT/${ACCOUNT_ID}/g" deployment.yaml - sed -i "s/DEPLOYMENTREGION/${AWS_REGION}/g" deployment.yaml - kubectl apply -f deployment.yaml -} - - -permissions () { - echo Attaching IAM policy to EKS nodes - - echo Fetching EC2 instance profile - profile=`aws ec2 describe-instances --filters "Name=tag-key,Values=eks:cluster-name" "Name=tag-value,Values=PetSite" | jq -r .Reservations[].Instances[].IamInstanceProfile.Arn | head -n 1 | cut -f 2 -d '/'` - echo Found instance profile: ${profile} - - role=`aws iam get-instance-profile --instance-profile-name ${profile} | jq -r .InstanceProfile.Roles[].RoleName` - echo Found role: ${role} - - if [ ! "`aws iam get-role-policy --role-name ${role} --policy-name evidently`" ] ; then - echo Attaching new Evidently policy to role - aws iam put-role-policy --role-name ${role} --policy-name evidently --policy-document file://$HOME/environment/workshopfiles/one-observability-demo/PetAdoptions/${service}/policy.json - else - echo Role has an Evidently policy already - fi -} - - -service="petfood" -deploy - -service="petfood-metric" -deploy - -permissions diff --git a/PetAdoptions/petfood/deployment.yaml b/PetAdoptions/petfood/deployment.yaml deleted file mode 100644 index bb70c0a7..00000000 --- a/PetAdoptions/petfood/deployment.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: petfood - labels: - app: petfood -spec: - replicas: 2 - selector: - matchLabels: - app: petfood - template: - metadata: - labels: - app: petfood - spec: - containers: - - env: - - name: AWS_XRAY_DAEMON_ADDRESS - value: xray-service:2000 - - name: AWS_DEFAULT_REGION - value: DEPLOYMENTREGION - name: petfood - image: DEPLOYMENTACCOUNT.dkr.ecr.DEPLOYMENTREGION.amazonaws.com/petfood:1 - ports: - - containerPort: 5000 -# livenessProbe: -# httpGet: -# path: /status -# port: 5000 -# initialDelaySeconds: 3 -# periodSeconds: 3 - ---- -apiVersion: v1 -kind: Service -metadata: - name: petfood - labels: - app: petfood -spec: - ports: - - port: 80 - protocol: TCP - targetPort: 5000 - selector: - app: petfood diff --git a/PetAdoptions/petfood/petfood.py b/PetAdoptions/petfood/petfood.py deleted file mode 100755 index 8060f1e0..00000000 --- a/PetAdoptions/petfood/petfood.py +++ /dev/null @@ -1,137 +0,0 @@ -"""Simple microservice to show Evidently features""" - -import json -import logging -import os -import random -import boto3 -from aws_xray_sdk.ext.flask.middleware import XRayMiddleware -from aws_xray_sdk.core import patch_all, xray_recorder -from flask import Flask, request - - -app = Flask(__name__) -plugins = ('EC2Plugin',) -xray_recorder.configure(plugins=plugins, service='petfood') -patch_all() -XRayMiddleware(app, xray_recorder) -xray_recorder.begin_segment('petfood') - - -class StructuredMessage: # pylint: disable=R0903 - """Use to make JSON formatted logging work well for CWL""" - def __init__(self, message, /, **kwargs): - self.message = message - self.kwargs = kwargs - - def __str__(self): - return f'{self.message} - {self.kwargs}' - - -_ = StructuredMessage -logging.basicConfig(level=os.getenv('LOG_LEVEL', 20), format='%(message)s') -logger = logging.getLogger() - - -class EvidentlyProject: - """Base for all Evidently interactions""" - - def __init__(self): - self.client = boto3.client('evidently') - self.project = os.getenv('EVIDENTLY_PROJECT', 'petfood') - self.upsell_feature = 'petfood-upsell' - self.upsell_text_feature = 'petfood-upsell-text' - - @xray_recorder.capture('evidently project_exists') - def project_exists(self): - """Returns False if the project does not currently exist""" - try: - response = self.client.get_project(project=self.project) - logger.info(_('checking for evidently project', response=response)) - return True - except self.client.exceptions.ResourceNotFoundException: - logger.warning(_('evidently project not found')) - return None - - @xray_recorder.capture('evidently get_upsell_evaluation') - def get_upsell_evaluation(self, entity_id): - """Gets the feature evaluation for petfood-upsell""" - try: - response = self.client.evaluate_feature( - entityId=entity_id, - feature=self.upsell_feature, - project=self.project - ) - return { - 'feature_enabled': response['value']['boolValue'], - 'variation': response['variation'] - } - except self.client.exceptions.ResourceNotFoundException: - logger.warning(_('evidently feature ' + self.upsell_feature + ' not found for project')) - return return_default() - - @xray_recorder.capture('evidently get_upsell_text') - def get_upsell_text(self, entity_id): - """Gets the feature evaluation for petfood-upsell-verbiage""" - try: - response = self.client.evaluate_feature( - entityId=entity_id, - feature=self.upsell_text_feature, - project=self.project - ) - logger.info(_('evidently ' + self.upsell_text_feature, response=response)) - return response['value']['stringValue'] - except self.client.exceptions.ResourceNotFoundException: - logger.warning(_('evidently feature ' + self.upsell_text_feature + ' not found for project')) - return 'Error getting upsell message - check that your feature exists in Evidently!' - - -@xray_recorder.capture('return_evidently_response') -def return_evidently_response(evidently): - """Create a response using an Evidently project""" - logger.info(_('building evidently response')) - entity_id = str(random.randint(1, 100)) - evaluation = evidently.get_upsell_evaluation(entity_id) - logger.warning(_('response from feature evaluation', evaluation=evaluation)) - response = json.dumps( - { - 'statusCode': 200, - 'message': evidently.get_upsell_text(entity_id), - 'variation': evaluation, - 'entityId': entity_id - } - ) - logger.warning(_('final response to request', response=response)) - return response - - -@xray_recorder.capture('return_default_response') -def return_default(): - """Returns the default response to the user""" - logger.warning(_('returning default response to the user')) - text = json.dumps( - { - 'message': 'Thank you for supporting our community!', - 'statusCode': 200 - } - ) - return text - - -@app.route('/') -def root_path(): - """Base URL for our handler""" - logger.info(_('raw request headers', headers=request.headers)) - evidently = EvidentlyProject() - project = evidently.project_exists() - if not project: - return return_default() - else: - return return_evidently_response(evidently) - - -@app.route('/status') -def status_path(): - """Used for health checks""" - logger.info(_('raw request headers', headers=request.headers)) - return json.dumps({'statusCode': 200, 'body': 'ok'}) diff --git a/PetAdoptions/petfood/requirements.txt b/PetAdoptions/petfood/requirements.txt deleted file mode 100644 index d822d977..00000000 --- a/PetAdoptions/petfood/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -aws-xray-sdk==2.9.0 -Flask==2.0.2 -boto3==1.20.21 -gunicorn==20.1.0 diff --git a/PetAdoptions/petlistadoptions-go/Dockerfile b/PetAdoptions/petlistadoptions-go/Dockerfile index e49a3bf9..f9f3d824 100644 --- a/PetAdoptions/petlistadoptions-go/Dockerfile +++ b/PetAdoptions/petlistadoptions-go/Dockerfile @@ -1,11 +1,11 @@ -FROM golang:1.20 as builder +FROM public.ecr.aws/docker/library/golang:1.20 as builder WORKDIR /go/src/app COPY . . ENV GOPROXY=https://goproxy.io,direct RUN go get . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . -FROM alpine:latest +FROM public.ecr.aws/docker/library/alpine:latest WORKDIR /app RUN apk --no-cache add ca-certificates COPY --from=builder /go/src/app/app . diff --git a/PetAdoptions/petsearch-java/Dockerfile b/PetAdoptions/petsearch-java/Dockerfile index bfd341d1..a156070d 100644 --- a/PetAdoptions/petsearch-java/Dockerfile +++ b/PetAdoptions/petsearch-java/Dockerfile @@ -1,4 +1,4 @@ -FROM gradle:7.3-jdk17 as build +FROM public.ecr.aws/docker/library/gradle:7.3-jdk17 as build WORKDIR /app COPY ./build.gradle ./build.gradle @@ -8,7 +8,7 @@ COPY ./settings.gradle ./settings.gradle ENV GRADLE_OPTS "-Dorg.gradle.daemon=false" RUN gradle build -DexcludeTags='integration' -FROM amazoncorretto:17-alpine +FROM public.ecr.aws/docker/library/amazoncorretto:17-alpine WORKDIR /app ADD https://github.com/aws-observability/aws-otel-java-instrumentation/releases/download/v1.21.1/aws-opentelemetry-agent.jar /app/aws-opentelemetry-agent.jar diff --git a/PetAdoptions/petsite/.vscode/launch.json b/PetAdoptions/petsite/.vscode/launch.json deleted file mode 100644 index f719590e..00000000 --- a/PetAdoptions/petsite/.vscode/launch.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (web)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/petsite/bin/Debug/netcoreapp3.0/PetSite.dll", - "args": [], - "cwd": "${workspaceFolder}/petsite", - "stopAtEntry": false, - // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser - "serverReadyAction": { - "action": "openExternally", - "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)" - }, - "env": { - "ASPNETCORE_ENVIRONMENT": "Development" - }, - "sourceFileMap": { - "/Views": "${workspaceFolder}/Views" - } - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/PetAdoptions/petsite/.vscode/tasks.json b/PetAdoptions/petsite/.vscode/tasks.json deleted file mode 100644 index 6a63c7b7..00000000 --- a/PetAdoptions/petsite/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/petsite/PetSite.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/petsite/PetSite.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/petsite/PetSite.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/PetAdoptions/petsite/petsite/Controllers/AdoptionController.cs b/PetAdoptions/petsite/Controllers/AdoptionController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/AdoptionController.cs rename to PetAdoptions/petsite/Controllers/AdoptionController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/HealthController.cs b/PetAdoptions/petsite/Controllers/HealthController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/HealthController.cs rename to PetAdoptions/petsite/Controllers/HealthController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/HomeController.cs b/PetAdoptions/petsite/Controllers/HomeController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/HomeController.cs rename to PetAdoptions/petsite/Controllers/HomeController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/PaymentController.cs b/PetAdoptions/petsite/Controllers/PaymentController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/PaymentController.cs rename to PetAdoptions/petsite/Controllers/PaymentController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/PetFoodController.cs b/PetAdoptions/petsite/Controllers/PetFoodController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/PetFoodController.cs rename to PetAdoptions/petsite/Controllers/PetFoodController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/PetHistoryController.cs b/PetAdoptions/petsite/Controllers/PetHistoryController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/PetHistoryController.cs rename to PetAdoptions/petsite/Controllers/PetHistoryController.cs diff --git a/PetAdoptions/petsite/petsite/Controllers/PetListAdoptionsController.cs b/PetAdoptions/petsite/Controllers/PetListAdoptionsController.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Controllers/PetListAdoptionsController.cs rename to PetAdoptions/petsite/Controllers/PetListAdoptionsController.cs diff --git a/PetAdoptions/petsite/petsite/Dockerfile b/PetAdoptions/petsite/Dockerfile similarity index 100% rename from PetAdoptions/petsite/petsite/Dockerfile rename to PetAdoptions/petsite/Dockerfile diff --git a/PetAdoptions/petsite/petsite/Models/ErrorViewModel.cs b/PetAdoptions/petsite/Models/ErrorViewModel.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Models/ErrorViewModel.cs rename to PetAdoptions/petsite/Models/ErrorViewModel.cs diff --git a/PetAdoptions/petsite/petsite/PetSite.csproj b/PetAdoptions/petsite/PetSite.csproj similarity index 100% rename from PetAdoptions/petsite/petsite/PetSite.csproj rename to PetAdoptions/petsite/PetSite.csproj diff --git a/PetAdoptions/petsite/petsite/Program.cs b/PetAdoptions/petsite/Program.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Program.cs rename to PetAdoptions/petsite/Program.cs diff --git a/PetAdoptions/petsite/petsite/Properties/launchSettings.json b/PetAdoptions/petsite/Properties/launchSettings.json similarity index 100% rename from PetAdoptions/petsite/petsite/Properties/launchSettings.json rename to PetAdoptions/petsite/Properties/launchSettings.json diff --git a/PetAdoptions/petsite/petsite/PutParams.cs b/PetAdoptions/petsite/PutParams.cs similarity index 100% rename from PetAdoptions/petsite/petsite/PutParams.cs rename to PetAdoptions/petsite/PutParams.cs diff --git a/PetAdoptions/petsite/petsite/SearchParams.cs b/PetAdoptions/petsite/SearchParams.cs similarity index 100% rename from PetAdoptions/petsite/petsite/SearchParams.cs rename to PetAdoptions/petsite/SearchParams.cs diff --git a/PetAdoptions/petsite/petsite/Startup.cs b/PetAdoptions/petsite/Startup.cs similarity index 100% rename from PetAdoptions/petsite/petsite/Startup.cs rename to PetAdoptions/petsite/Startup.cs diff --git a/PetAdoptions/petsite/petsite/SystemsManagerConfigurationProviderWithReload.cs b/PetAdoptions/petsite/SystemsManagerConfigurationProviderWithReload.cs similarity index 100% rename from PetAdoptions/petsite/petsite/SystemsManagerConfigurationProviderWithReload.cs rename to PetAdoptions/petsite/SystemsManagerConfigurationProviderWithReload.cs diff --git a/PetAdoptions/petsite/petsite/ViewModels/Pets.cs b/PetAdoptions/petsite/ViewModels/Pets.cs similarity index 100% rename from PetAdoptions/petsite/petsite/ViewModels/Pets.cs rename to PetAdoptions/petsite/ViewModels/Pets.cs diff --git a/PetAdoptions/petsite/petsite/Views/Adoption/Index.cshtml b/PetAdoptions/petsite/Views/Adoption/Index.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Adoption/Index.cshtml rename to PetAdoptions/petsite/Views/Adoption/Index.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Home/HouseKeeping.cshtml b/PetAdoptions/petsite/Views/Home/HouseKeeping.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Home/HouseKeeping.cshtml rename to PetAdoptions/petsite/Views/Home/HouseKeeping.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Home/Index.cshtml b/PetAdoptions/petsite/Views/Home/Index.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Home/Index.cshtml rename to PetAdoptions/petsite/Views/Home/Index.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Home/Privacy.cshtml b/PetAdoptions/petsite/Views/Home/Privacy.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Home/Privacy.cshtml rename to PetAdoptions/petsite/Views/Home/Privacy.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Payment/Index.cshtml b/PetAdoptions/petsite/Views/Payment/Index.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Payment/Index.cshtml rename to PetAdoptions/petsite/Views/Payment/Index.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/PetHistory/Index.cshtml b/PetAdoptions/petsite/Views/PetHistory/Index.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/PetHistory/Index.cshtml rename to PetAdoptions/petsite/Views/PetHistory/Index.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/PetListAdoptions/Index.cshtml b/PetAdoptions/petsite/Views/PetListAdoptions/Index.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/PetListAdoptions/Index.cshtml rename to PetAdoptions/petsite/Views/PetListAdoptions/Index.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Shared/Error.cshtml b/PetAdoptions/petsite/Views/Shared/Error.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Shared/Error.cshtml rename to PetAdoptions/petsite/Views/Shared/Error.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Shared/_AdoptionItem.cshtml b/PetAdoptions/petsite/Views/Shared/_AdoptionItem.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Shared/_AdoptionItem.cshtml rename to PetAdoptions/petsite/Views/Shared/_AdoptionItem.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Shared/_Layout.cshtml b/PetAdoptions/petsite/Views/Shared/_Layout.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Shared/_Layout.cshtml rename to PetAdoptions/petsite/Views/Shared/_Layout.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Shared/_PetItem.cshtml b/PetAdoptions/petsite/Views/Shared/_PetItem.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Shared/_PetItem.cshtml rename to PetAdoptions/petsite/Views/Shared/_PetItem.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/Shared/_ValidationScriptsPartial.cshtml b/PetAdoptions/petsite/Views/Shared/_ValidationScriptsPartial.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/Shared/_ValidationScriptsPartial.cshtml rename to PetAdoptions/petsite/Views/Shared/_ValidationScriptsPartial.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/_ViewImports.cshtml b/PetAdoptions/petsite/Views/_ViewImports.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/_ViewImports.cshtml rename to PetAdoptions/petsite/Views/_ViewImports.cshtml diff --git a/PetAdoptions/petsite/petsite/Views/_ViewStart.cshtml b/PetAdoptions/petsite/Views/_ViewStart.cshtml similarity index 100% rename from PetAdoptions/petsite/petsite/Views/_ViewStart.cshtml rename to PetAdoptions/petsite/Views/_ViewStart.cshtml diff --git a/PetAdoptions/petsite/petsite/appsettings.Development.json b/PetAdoptions/petsite/appsettings.Development.json similarity index 100% rename from PetAdoptions/petsite/petsite/appsettings.Development.json rename to PetAdoptions/petsite/appsettings.Development.json diff --git a/PetAdoptions/petsite/petsite/appsettings.json b/PetAdoptions/petsite/appsettings.json similarity index 100% rename from PetAdoptions/petsite/petsite/appsettings.json rename to PetAdoptions/petsite/appsettings.json diff --git a/PetAdoptions/petsite/petsite/bundleconfig.json b/PetAdoptions/petsite/bundleconfig.json similarity index 100% rename from PetAdoptions/petsite/petsite/bundleconfig.json rename to PetAdoptions/petsite/bundleconfig.json diff --git a/PetAdoptions/petsite/petsite/compilerconfig.json b/PetAdoptions/petsite/compilerconfig.json similarity index 100% rename from PetAdoptions/petsite/petsite/compilerconfig.json rename to PetAdoptions/petsite/compilerconfig.json diff --git a/PetAdoptions/petsite/petsite/compilerconfig.json.defaults b/PetAdoptions/petsite/compilerconfig.json.defaults similarity index 100% rename from PetAdoptions/petsite/petsite/compilerconfig.json.defaults rename to PetAdoptions/petsite/compilerconfig.json.defaults diff --git a/PetAdoptions/petsite/petsite/wwwroot/css/petstyles.css b/PetAdoptions/petsite/wwwroot/css/petstyles.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/css/petstyles.css rename to PetAdoptions/petsite/wwwroot/css/petstyles.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/css/site.css b/PetAdoptions/petsite/wwwroot/css/site.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/css/site.css rename to PetAdoptions/petsite/wwwroot/css/site.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/css/site.min.css b/PetAdoptions/petsite/wwwroot/css/site.min.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/css/site.min.css rename to PetAdoptions/petsite/wwwroot/css/site.min.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/favicon.ico b/PetAdoptions/petsite/wwwroot/favicon.ico similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/favicon.ico rename to PetAdoptions/petsite/wwwroot/favicon.ico diff --git a/PetAdoptions/petsite/petsite/wwwroot/images/arrow-down.png b/PetAdoptions/petsite/wwwroot/images/arrow-down.png similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/images/arrow-down.png rename to PetAdoptions/petsite/wwwroot/images/arrow-down.png diff --git a/PetAdoptions/petsite/petsite/wwwroot/images/arrow-right.svg b/PetAdoptions/petsite/wwwroot/images/arrow-right.svg similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/images/arrow-right.svg rename to PetAdoptions/petsite/wwwroot/images/arrow-right.svg diff --git a/PetAdoptions/petsite/petsite/wwwroot/images/brand.png b/PetAdoptions/petsite/wwwroot/images/brand.png similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/images/brand.png rename to PetAdoptions/petsite/wwwroot/images/brand.png diff --git a/PetAdoptions/petsite/petsite/wwwroot/images/main_banner.png b/PetAdoptions/petsite/wwwroot/images/main_banner.png similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/images/main_banner.png rename to PetAdoptions/petsite/wwwroot/images/main_banner.png diff --git a/PetAdoptions/petsite/petsite/wwwroot/images/main_banner_text.png b/PetAdoptions/petsite/wwwroot/images/main_banner_text.png similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/images/main_banner_text.png rename to PetAdoptions/petsite/wwwroot/images/main_banner_text.png diff --git a/PetAdoptions/petsite/petsite/wwwroot/js/site.js b/PetAdoptions/petsite/wwwroot/js/site.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/js/site.js rename to PetAdoptions/petsite/wwwroot/js/site.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/js/site.min.js b/PetAdoptions/petsite/wwwroot/js/site.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/js/site.min.js rename to PetAdoptions/petsite/wwwroot/js/site.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/LICENSE b/PetAdoptions/petsite/wwwroot/lib/bootstrap/LICENSE similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/LICENSE rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/LICENSE diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-grid.min.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/css/bootstrap.min.css.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.js.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.bundle.min.js.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.js.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js.map b/PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js.map rename to PetAdoptions/petsite/wwwroot/lib/bootstrap/dist/js/bootstrap.min.js.map diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt b/PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/LICENSE.md b/PetAdoptions/petsite/wwwroot/lib/jquery-validation/LICENSE.md similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/LICENSE.md rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation/LICENSE.md diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.min.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.min.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/additional-methods.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js b/PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js rename to PetAdoptions/petsite/wwwroot/lib/jquery-validation/dist/jquery.validate.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery/LICENSE.txt b/PetAdoptions/petsite/wwwroot/lib/jquery/LICENSE.txt similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery/LICENSE.txt rename to PetAdoptions/petsite/wwwroot/lib/jquery/LICENSE.txt diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.js b/PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.js rename to PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.min.js b/PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.min.js similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.min.js rename to PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.min.js diff --git a/PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.min.map b/PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.min.map similarity index 100% rename from PetAdoptions/petsite/petsite/wwwroot/lib/jquery/dist/jquery.min.map rename to PetAdoptions/petsite/wwwroot/lib/jquery/dist/jquery.min.map diff --git a/PetAdoptions/trafficgenerator/.idea/.gitignore b/PetAdoptions/trafficgenerator/.idea/.gitignore deleted file mode 100644 index e69de29b..00000000 diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/.gitignore b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/.gitignore deleted file mode 100644 index 5c98b428..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/contentModel.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/contentModel.xml deleted file mode 100644 index c60d3791..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/contentModel.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/encodings.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/encodings.xml deleted file mode 100644 index df87cf95..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/indexLayout.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/indexLayout.xml deleted file mode 100644 index 27ba142e..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/modules.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/modules.xml deleted file mode 100644 index 7fcbe8d8..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/projectSettingsUpdater.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/projectSettingsUpdater.xml deleted file mode 100644 index 7515e760..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/projectSettingsUpdater.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/vcs.xml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/vcs.xml deleted file mode 100644 index 6c0b8635..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/riderModule.iml b/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/riderModule.iml deleted file mode 100644 index 1a4e0d95..00000000 --- a/PetAdoptions/trafficgenerator/.idea/.idea.trafficgenerator/riderModule.iml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/Dockerfile b/PetAdoptions/trafficgenerator/Dockerfile similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/Dockerfile rename to PetAdoptions/trafficgenerator/Dockerfile diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/PetData.cs b/PetAdoptions/trafficgenerator/PetData.cs similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/PetData.cs rename to PetAdoptions/trafficgenerator/PetData.cs diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/Program.cs b/PetAdoptions/trafficgenerator/Program.cs similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/Program.cs rename to PetAdoptions/trafficgenerator/Program.cs diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/Properties/launchSettings.json b/PetAdoptions/trafficgenerator/Properties/launchSettings.json similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/Properties/launchSettings.json rename to PetAdoptions/trafficgenerator/Properties/launchSettings.json diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/Startup.cs b/PetAdoptions/trafficgenerator/Startup.cs similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/Startup.cs rename to PetAdoptions/trafficgenerator/Startup.cs diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/Worker.cs b/PetAdoptions/trafficgenerator/Worker.cs similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/Worker.cs rename to PetAdoptions/trafficgenerator/Worker.cs diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/appsettings.Development.json b/PetAdoptions/trafficgenerator/appsettings.Development.json similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/appsettings.Development.json rename to PetAdoptions/trafficgenerator/appsettings.Development.json diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/appsettings.json b/PetAdoptions/trafficgenerator/appsettings.json similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/appsettings.json rename to PetAdoptions/trafficgenerator/appsettings.json diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/docker-compose.yml b/PetAdoptions/trafficgenerator/docker-compose.yml similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/docker-compose.yml rename to PetAdoptions/trafficgenerator/docker-compose.yml diff --git a/PetAdoptions/trafficgenerator/trafficgenerator/trafficgenerator.csproj b/PetAdoptions/trafficgenerator/trafficgenerator.csproj similarity index 100% rename from PetAdoptions/trafficgenerator/trafficgenerator/trafficgenerator.csproj rename to PetAdoptions/trafficgenerator/trafficgenerator.csproj diff --git a/PetAdoptions/trafficgenerator/trafficgenerator.sln b/PetAdoptions/trafficgenerator/trafficgenerator.sln deleted file mode 100644 index e2dd0ca9..00000000 --- a/PetAdoptions/trafficgenerator/trafficgenerator.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "trafficgenerator", "trafficgenerator\trafficgenerator.csproj", "{C872A202-C201-46EC-AA25-C5FB9EF5AD4A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C872A202-C201-46EC-AA25-C5FB9EF5AD4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C872A202-C201-46EC-AA25-C5FB9EF5AD4A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C872A202-C201-46EC-AA25-C5FB9EF5AD4A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C872A202-C201-46EC-AA25-C5FB9EF5AD4A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/bootstrap.yaml b/bootstrap.yaml new file mode 100644 index 00000000..505cff01 --- /dev/null +++ b/bootstrap.yaml @@ -0,0 +1,622 @@ +Description: This stack includes resources needed to deploy AWS CDK apps into this environment +Parameters: + TrustedAccounts: + Description: List of AWS accounts that are trusted to publish assets and deploy stacks to this environment + Default: "" + Type: CommaDelimitedList + TrustedAccountsForLookup: + Description: List of AWS accounts that are trusted to look up values in this environment + Default: "" + Type: CommaDelimitedList + CloudFormationExecutionPolicies: + Description: List of the ManagedPolicy ARN(s) to attach to the CloudFormation deployment role + Default: "" + Type: CommaDelimitedList + FileAssetsBucketName: + Description: The name of the S3 bucket used for file assets + Default: "" + Type: String + FileAssetsBucketKmsKeyId: + Description: Empty to create a new key (default), 'AWS_MANAGED_KEY' to use a managed S3 key, or the ID/ARN of an existing key. + Default: "" + Type: String + ContainerAssetsRepositoryName: + Description: A user-provided custom name to use for the container assets ECR repository + Default: "" + Type: String + Qualifier: + Description: An identifier to distinguish multiple bootstrap stacks in the same environment + Default: hnb659fds + Type: String + AllowedPattern: "[A-Za-z0-9_-]{1,10}" + ConstraintDescription: Qualifier must be an alphanumeric identifier of at most 10 characters + PublicAccessBlockConfiguration: + Description: Whether or not to enable S3 Staging Bucket Public Access Block Configuration + Default: "true" + Type: String + AllowedValues: + - "true" + - "false" + InputPermissionsBoundary: + Description: Whether or not to use either the CDK supplied or custom permissions boundary + Default: "" + Type: String + UseExamplePermissionsBoundary: + Default: "false" + AllowedValues: + - "true" + - "false" + Type: String + BootstrapVariant: + Type: String + Default: "AWS CDK: Default Resources" + Description: Describe the provenance of the resources in this bootstrap stack. Change this when you customize the template. To prevent accidents, the CDK CLI will not overwrite bootstrap stacks with a different variant. +Conditions: + HasTrustedAccounts: + Fn::Not: + - Fn::Equals: + - "" + - Fn::Join: + - "" + - Ref: TrustedAccounts + HasTrustedAccountsForLookup: + Fn::Not: + - Fn::Equals: + - "" + - Fn::Join: + - "" + - Ref: TrustedAccountsForLookup + HasCloudFormationExecutionPolicies: + Fn::Not: + - Fn::Equals: + - "" + - Fn::Join: + - "" + - Ref: CloudFormationExecutionPolicies + HasCustomFileAssetsBucketName: + Fn::Not: + - Fn::Equals: + - "" + - Ref: FileAssetsBucketName + CreateNewKey: + Fn::Equals: + - "" + - Ref: FileAssetsBucketKmsKeyId + UseAwsManagedKey: + Fn::Equals: + - AWS_MANAGED_KEY + - Ref: FileAssetsBucketKmsKeyId + ShouldCreatePermissionsBoundary: + Fn::Equals: + - "true" + - Ref: UseExamplePermissionsBoundary + PermissionsBoundarySet: + Fn::Not: + - Fn::Equals: + - "" + - Ref: InputPermissionsBoundary + HasCustomContainerAssetsRepositoryName: + Fn::Not: + - Fn::Equals: + - "" + - Ref: ContainerAssetsRepositoryName + UsePublicAccessBlockConfiguration: + Fn::Equals: + - "true" + - Ref: PublicAccessBlockConfiguration +Resources: + FileAssetsBucketEncryptionKey: + Type: AWS::KMS::Key + Properties: + KeyPolicy: + Statement: + - Action: + - kms:Create* + - kms:Describe* + - kms:Enable* + - kms:List* + - kms:Put* + - kms:Update* + - kms:Revoke* + - kms:Disable* + - kms:Get* + - kms:Delete* + - kms:ScheduleKeyDeletion + - kms:CancelKeyDeletion + - kms:GenerateDataKey + - kms:TagResource + - kms:UntagResource + Effect: Allow + Principal: + AWS: + Ref: AWS::AccountId + Resource: "*" + - Action: + - kms:Decrypt + - kms:DescribeKey + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + Effect: Allow + Principal: + AWS: "*" + Resource: "*" + Condition: + StringEquals: + kms:CallerAccount: + Ref: AWS::AccountId + kms:ViaService: + - Fn::Sub: s3.${AWS::Region}.amazonaws.com + - Action: + - kms:Decrypt + - kms:DescribeKey + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + Effect: Allow + Principal: + AWS: + Fn::Sub: ${FilePublishingRole.Arn} + Resource: "*" + Condition: CreateNewKey + FileAssetsBucketEncryptionKeyAlias: + Condition: CreateNewKey + Type: AWS::KMS::Alias + Properties: + AliasName: + Fn::Sub: alias/cdk-${Qualifier}-assets-key + TargetKeyId: + Ref: FileAssetsBucketEncryptionKey + StagingBucket: + Type: AWS::S3::Bucket + Properties: + BucketName: + Fn::If: + - HasCustomFileAssetsBucketName + - Fn::Sub: ${FileAssetsBucketName} + - Fn::Sub: cdk-${Qualifier}-assets-${AWS::AccountId}-${AWS::Region} + AccessControl: Private + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: aws:kms + KMSMasterKeyID: + Fn::If: + - CreateNewKey + - Fn::Sub: ${FileAssetsBucketEncryptionKey.Arn} + - Fn::If: + - UseAwsManagedKey + - Ref: AWS::NoValue + - Fn::Sub: ${FileAssetsBucketKmsKeyId} + PublicAccessBlockConfiguration: + Fn::If: + - UsePublicAccessBlockConfiguration + - BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true + - Ref: AWS::NoValue + VersioningConfiguration: + Status: Enabled + LifecycleConfiguration: + Rules: + - Id: CleanupOldVersions + Status: Enabled + NoncurrentVersionExpiration: + NoncurrentDays: 365 + UpdateReplacePolicy: Retain + DeletionPolicy: Retain + StagingBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: + Ref: StagingBucket + PolicyDocument: + Id: AccessControl + Version: "2012-10-17" + Statement: + - Sid: AllowSSLRequestsOnly + Action: s3:* + Effect: Deny + Resource: + - Fn::Sub: ${StagingBucket.Arn} + - Fn::Sub: ${StagingBucket.Arn}/* + Condition: + Bool: + aws:SecureTransport: "false" + Principal: "*" + ContainerAssetsRepository: + Type: AWS::ECR::Repository + Properties: + ImageTagMutability: IMMUTABLE + LifecyclePolicy: + LifecyclePolicyText: | + { + "rules": [ + { + "rulePriority": 1, + "description": "Untagged images should not exist, but expire any older than one year", + "selection": { + "tagStatus": "untagged", + "countType": "sinceImagePushed", + "countUnit": "days", + "countNumber": 365 + }, + "action": { "type": "expire" } + } + ] + } + RepositoryName: + Fn::If: + - HasCustomContainerAssetsRepositoryName + - Fn::Sub: ${ContainerAssetsRepositoryName} + - Fn::Sub: cdk-${Qualifier}-container-assets-${AWS::AccountId}-${AWS::Region} + RepositoryPolicyText: + Version: "2012-10-17" + Statement: + - Sid: LambdaECRImageRetrievalPolicy + Effect: Allow + Principal: + Service: lambda.amazonaws.com + Action: + - ecr:BatchGetImage + - ecr:GetDownloadUrlForLayer + Condition: + StringLike: + aws:sourceArn: + Fn::Sub: arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:* + FilePublishingRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: AWS::AccountId + - Fn::If: + - HasTrustedAccounts + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: TrustedAccounts + - Ref: AWS::NoValue + RoleName: + Fn::Sub: cdk-${Qualifier}-file-publishing-role-${AWS::AccountId}-${AWS::Region} + Tags: + - Key: aws-cdk:bootstrap-role + Value: file-publishing + ImagePublishingRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: AWS::AccountId + - Fn::If: + - HasTrustedAccounts + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: TrustedAccounts + - Ref: AWS::NoValue + RoleName: + Fn::Sub: cdk-${Qualifier}-image-publishing-role-${AWS::AccountId}-${AWS::Region} + Tags: + - Key: aws-cdk:bootstrap-role + Value: image-publishing + LookupRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: AWS::AccountId + - Fn::If: + - HasTrustedAccountsForLookup + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: TrustedAccountsForLookup + - Ref: AWS::NoValue + - Fn::If: + - HasTrustedAccounts + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: TrustedAccounts + - Ref: AWS::NoValue + RoleName: + Fn::Sub: cdk-${Qualifier}-lookup-role-${AWS::AccountId}-${AWS::Region} + ManagedPolicyArns: + - Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/ReadOnlyAccess + Policies: + - PolicyDocument: + Statement: + - Sid: DontReadSecrets + Effect: Deny + Action: + - kms:Decrypt + Resource: "*" + Version: "2012-10-17" + PolicyName: LookupRolePolicy + Tags: + - Key: aws-cdk:bootstrap-role + Value: lookup + FilePublishingRoleDefaultPolicy: + Type: AWS::IAM::Policy + Properties: + PolicyDocument: + Statement: + - Action: + - s3:GetObject* + - s3:GetBucket* + - s3:GetEncryptionConfiguration + - s3:List* + - s3:DeleteObject* + - s3:PutObject* + - s3:Abort* + Resource: + - Fn::Sub: ${StagingBucket.Arn} + - Fn::Sub: ${StagingBucket.Arn}/* + Condition: + StringEquals: + aws:ResourceAccount: + - Fn::Sub: ${AWS::AccountId} + Effect: Allow + - Action: + - kms:Decrypt + - kms:DescribeKey + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + Effect: Allow + Resource: + Fn::If: + - CreateNewKey + - Fn::Sub: ${FileAssetsBucketEncryptionKey.Arn} + - Fn::Sub: arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${FileAssetsBucketKmsKeyId} + Version: "2012-10-17" + Roles: + - Ref: FilePublishingRole + PolicyName: + Fn::Sub: cdk-${Qualifier}-file-publishing-role-default-policy-${AWS::AccountId}-${AWS::Region} + ImagePublishingRoleDefaultPolicy: + Type: AWS::IAM::Policy + Properties: + PolicyDocument: + Statement: + - Action: + - ecr:PutImage + - ecr:InitiateLayerUpload + - ecr:UploadLayerPart + - ecr:CompleteLayerUpload + - ecr:BatchCheckLayerAvailability + - ecr:DescribeRepositories + - ecr:DescribeImages + - ecr:BatchGetImage + - ecr:GetDownloadUrlForLayer + Resource: + Fn::Sub: ${ContainerAssetsRepository.Arn} + Effect: Allow + - Action: + - ecr:GetAuthorizationToken + Resource: "*" + Effect: Allow + Version: "2012-10-17" + Roles: + - Ref: ImagePublishingRole + PolicyName: + Fn::Sub: cdk-${Qualifier}-image-publishing-role-default-policy-${AWS::AccountId}-${AWS::Region} + DeploymentActionRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: AWS::AccountId + - Fn::If: + - HasTrustedAccounts + - Action: sts:AssumeRole + Effect: Allow + Principal: + AWS: + Ref: TrustedAccounts + - Ref: AWS::NoValue + Policies: + - PolicyDocument: + Statement: + - Sid: CloudFormationPermissions + Effect: Allow + Action: + - cloudformation:CreateChangeSet + - cloudformation:DeleteChangeSet + - cloudformation:DescribeChangeSet + - cloudformation:DescribeStacks + - cloudformation:ExecuteChangeSet + - cloudformation:CreateStack + - cloudformation:UpdateStack + Resource: "*" + - Sid: PipelineCrossAccountArtifactsBucket + Effect: Allow + Action: + - s3:GetObject* + - s3:GetBucket* + - s3:List* + - s3:Abort* + - s3:DeleteObject* + - s3:PutObject* + Resource: "*" + Condition: + StringNotEquals: + s3:ResourceAccount: + Ref: AWS::AccountId + - Sid: PipelineCrossAccountArtifactsKey + Effect: Allow + Action: + - kms:Decrypt + - kms:DescribeKey + - kms:Encrypt + - kms:ReEncrypt* + - kms:GenerateDataKey* + Resource: "*" + Condition: + StringEquals: + kms:ViaService: + Fn::Sub: s3.${AWS::Region}.amazonaws.com + - Action: iam:PassRole + Resource: + Fn::Sub: ${CloudFormationExecutionRole.Arn} + Effect: Allow + - Sid: CliPermissions + Action: + - cloudformation:DescribeStackEvents + - cloudformation:GetTemplate + - cloudformation:DeleteStack + - cloudformation:UpdateTerminationProtection + - sts:GetCallerIdentity + - cloudformation:GetTemplateSummary + Resource: "*" + Effect: Allow + - Sid: CliStagingBucket + Effect: Allow + Action: + - s3:GetObject* + - s3:GetBucket* + - s3:List* + Resource: + - Fn::Sub: ${StagingBucket.Arn} + - Fn::Sub: ${StagingBucket.Arn}/* + - Sid: ReadVersion + Effect: Allow + Action: + - ssm:GetParameter + - ssm:GetParameters + Resource: + - Fn::Sub: arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter${CdkBootstrapVersion} + Version: "2012-10-17" + PolicyName: default + RoleName: + Fn::Sub: cdk-${Qualifier}-deploy-role-${AWS::AccountId}-${AWS::Region} + Tags: + - Key: aws-cdk:bootstrap-role + Value: deploy + CloudFormationExecutionRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: cloudformation.amazonaws.com + Version: "2012-10-17" + ManagedPolicyArns: + Fn::If: + - HasCloudFormationExecutionPolicies + - Ref: CloudFormationExecutionPolicies + - Fn::If: + - HasTrustedAccounts + - Ref: AWS::NoValue + - - Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess + RoleName: + Fn::Sub: cdk-${Qualifier}-cfn-exec-role-${AWS::AccountId}-${AWS::Region} + PermissionsBoundary: + Fn::If: + - PermissionsBoundarySet + - Fn::Sub: arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${InputPermissionsBoundary} + - Ref: AWS::NoValue + CdkBoostrapPermissionsBoundaryPolicy: + Condition: ShouldCreatePermissionsBoundary + Type: AWS::IAM::ManagedPolicy + Properties: + PolicyDocument: + Statement: + - Sid: ExplicitAllowAll + Action: + - "*" + Effect: Allow + Resource: "*" + - Sid: DenyAccessIfRequiredPermBoundaryIsNotBeingApplied + Action: + - iam:CreateUser + - iam:CreateRole + - iam:PutRolePermissionsBoundary + - iam:PutUserPermissionsBoundary + Condition: + StringNotEquals: + iam:PermissionsBoundary: + Fn::Sub: arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/cdk-${Qualifier}-permissions-boundary-${AWS::AccountId}-${AWS::Region} + Effect: Deny + Resource: "*" + - Sid: DenyPermBoundaryIAMPolicyAlteration + Action: + - iam:CreatePolicyVersion + - iam:DeletePolicy + - iam:DeletePolicyVersion + - iam:SetDefaultPolicyVersion + Effect: Deny + Resource: + Fn::Sub: arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/cdk-${Qualifier}-permissions-boundary-${AWS::AccountId}-${AWS::Region} + - Sid: DenyRemovalOfPermBoundaryFromAnyUserOrRole + Action: + - iam:DeleteUserPermissionsBoundary + - iam:DeleteRolePermissionsBoundary + Effect: Deny + Resource: "*" + Version: "2012-10-17" + Description: Bootstrap Permission Boundary + ManagedPolicyName: + Fn::Sub: cdk-${Qualifier}-permissions-boundary-${AWS::AccountId}-${AWS::Region} + Path: / + CdkBootstrapVersion: + Type: AWS::SSM::Parameter + Properties: + Type: String + Name: + Fn::Sub: /cdk-bootstrap/${Qualifier}/version + Value: "21" +Outputs: + BucketName: + Description: The name of the S3 bucket owned by the CDK toolkit stack + Value: + Fn::Sub: ${StagingBucket} + BucketDomainName: + Description: The domain name of the S3 bucket owned by the CDK toolkit stack + Value: + Fn::Sub: ${StagingBucket.RegionalDomainName} + FileAssetKeyArn: + Description: The ARN of the KMS key used to encrypt the asset bucket (deprecated) + Value: + Fn::If: + - CreateNewKey + - Fn::Sub: ${FileAssetsBucketEncryptionKey.Arn} + - Fn::Sub: ${FileAssetsBucketKmsKeyId} + Export: + Name: + Fn::Sub: CdkBootstrap-${Qualifier}-FileAssetKeyArn + ImageRepositoryName: + Description: The name of the ECR repository which hosts docker image assets + Value: + Fn::Sub: ${ContainerAssetsRepository} + BootstrapVersion: + Description: The version of the bootstrap resources that are currently mastered in this stack + Value: + Fn::GetAtt: + - CdkBootstrapVersion + - Value + diff --git a/codepipeline-stack.yaml b/codepipeline-stack.yaml index 8a3a7bee..b75a63cc 100644 --- a/codepipeline-stack.yaml +++ b/codepipeline-stack.yaml @@ -1,28 +1,5 @@ Description: One Observability Workshop Pipeline Parameters: - EnvironmentName: - Description: An environment name that is prefixed to resource names - Type: String - Default: OneObservability - - VpcCIDR: - Description: Please enter the IP range (CIDR notation) for this VPC - Type: String - Default: 10.192.0.0/16 - - PublicSubnet1CIDR: - Description: Please enter the IP range (CIDR notation) for the public subnet in the first Availability Zone - Type: String - Default: 10.192.10.0/24 - - PrivateSubnet1CIDR: - Description: Please enter the IP range (CIDR notation) for the private subnet in the first Availability Zone - Type: String - Default: 10.192.20.0/24 - - UserRoleArn: - Description: "ARN of the Role that will have access to manage the EKS Cluster" - Type: String GithubBranch: Description: "Source branch to use for CodePipeline deployment" @@ -31,167 +8,7 @@ Parameters: Resources: - VPC: - Type: AWS::EC2::VPC - Properties: - CidrBlock: !Ref VpcCIDR - EnableDnsSupport: true - EnableDnsHostnames: true - Tags: - - Key: Name - Value: !Ref EnvironmentName - - InternetGateway: - Type: AWS::EC2::InternetGateway - Properties: - Tags: - - Key: Name - Value: !Ref EnvironmentName - - InternetGatewayAttachment: - Type: AWS::EC2::VPCGatewayAttachment - Properties: - InternetGatewayId: !Ref InternetGateway - VpcId: !Ref VPC - - PublicSubnet1: - Type: AWS::EC2::Subnet - Properties: - VpcId: !Ref VPC - AvailabilityZone: !Select [ 0, !GetAZs '' ] - CidrBlock: !Ref PublicSubnet1CIDR - MapPublicIpOnLaunch: true - Tags: - - Key: Name - Value: !Sub ${EnvironmentName} Public Subnet (AZ1) - - - PrivateSubnet1: - Type: AWS::EC2::Subnet - Properties: - VpcId: !Ref VPC - AvailabilityZone: !Select [ 0, !GetAZs '' ] - CidrBlock: !Ref PrivateSubnet1CIDR - MapPublicIpOnLaunch: false - Tags: - - Key: Name - Value: !Sub ${EnvironmentName} Private Subnet (AZ1) - - NatGateway1EIP: - Type: AWS::EC2::EIP - DependsOn: InternetGatewayAttachment - Properties: - Domain: vpc - - NatGateway1: - Type: AWS::EC2::NatGateway - Properties: - AllocationId: !GetAtt NatGateway1EIP.AllocationId - SubnetId: !Ref PublicSubnet1 - - - PublicRouteTable: - Type: AWS::EC2::RouteTable - Properties: - VpcId: !Ref VPC - Tags: - - Key: Name - Value: !Sub ${EnvironmentName} Public Routes - - DefaultPublicRoute: - Type: AWS::EC2::Route - DependsOn: InternetGatewayAttachment - Properties: - RouteTableId: !Ref PublicRouteTable - DestinationCidrBlock: 0.0.0.0/0 - GatewayId: !Ref InternetGateway - - PublicSubnet1RouteTableAssociation: - Type: AWS::EC2::SubnetRouteTableAssociation - Properties: - RouteTableId: !Ref PublicRouteTable - SubnetId: !Ref PublicSubnet1 - - PrivateRouteTable1: - Type: AWS::EC2::RouteTable - Properties: - VpcId: !Ref VPC - Tags: - - Key: Name - Value: !Sub ${EnvironmentName} Private Routes (AZ1) - - DefaultPrivateRoute1: - Type: AWS::EC2::Route - Properties: - RouteTableId: !Ref PrivateRouteTable1 - DestinationCidrBlock: 0.0.0.0/0 - NatGatewayId: !Ref NatGateway1 - - PrivateSubnet1RouteTableAssociation: - Type: AWS::EC2::SubnetRouteTableAssociation - Properties: - RouteTableId: !Ref PrivateRouteTable1 - SubnetId: !Ref PrivateSubnet1 - - - NoIngressSecurityGroup: - Type: AWS::EC2::SecurityGroup - Properties: - GroupName: "no-ingress-sg" - GroupDescription: "Security group with no ingress rule" - VpcId: !Ref VPC - - PipelineArtifactsBucket: - Type: AWS::S3::Bucket - Properties: - AccessControl: Private - PublicAccessBlockConfiguration: - BlockPublicAcls: true - BlockPublicPolicy: true - RestrictPublicBuckets: true - IgnorePublicAcls: true - DeletionPolicy: Retain - - PipelineRole: - Type: AWS::IAM::Role - Properties: - AssumeRolePolicyDocument: - Statement: - - Action: sts:AssumeRole - Effect: Allow - Principal: - Service: codepipeline.amazonaws.com - Version: "2012-10-17" - ManagedPolicyArns: - - arn:aws:iam::aws:policy/AdministratorAccess - - PipelineRoleDefaultPolicy: - Type: AWS::IAM::Policy - Properties: - PolicyDocument: - Statement: - - Action: - - s3:GetObject* - - s3:GetBucket* - - s3:List* - - s3:DeleteObject* - - s3:PutObject - - s3:Abort* - Effect: Allow - Resource: "*" - - Action: sts:AssumeRole - Effect: Allow - Resource: - Fn::GetAtt: - - PipelineDeployActionRole - - Arn - - Version: "2012-10-17" - PolicyName: PipelineRoleDefaultPolicy - Roles: - - Ref: PipelineRole - - PipelineDeployActionRole: + CodeDeployRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: @@ -204,7 +21,7 @@ Resources: ManagedPolicyArns: - arn:aws:iam::aws:policy/AdministratorAccess - PipelineDeployActionRoleDefaultPolicy: + CodeDeployRoleDefaultPolicy: Type: AWS::IAM::Policy Properties: PolicyDocument: @@ -233,16 +50,18 @@ Resources: Effect: Allow Resource: "*" Version: "2012-10-17" - PolicyName: PipelineDeployActionRoleDefaultPolicy + PolicyName: CodeDeployRoleDefaultPolicy Roles: - - Ref: PipelineDeployActionRole + - Ref: CodeDeployRole - PipelineDeployProject: + CodeBuildProject: Type: AWS::CodeBuild::Project Properties: + Name: "CDKPipelineInitialDeployment" + Description: "This Project runs the initial deployment of the CDK Self-mutating pipeline used for the One Observability Workshop IaC" Artifacts: - Type: CODEPIPELINE + Type: NO_ARTIFACTS TimeoutInMinutes: 90 Environment: ComputeType: BUILD_GENERAL1_SMALL @@ -251,22 +70,17 @@ Resources: PrivilegedMode: true Type: LINUX_CONTAINER EnvironmentVariables: - - Name: USER_ROLE_ARN - Type: PLAINTEXT - Value: !Ref UserRoleArn - Name: GITHUB_BRANCH Type: PLAINTEXT - Value: !Ref GithubBranch - # https://github.com/cdklabs/cdk-ecr-deployment/issues/478#issuecomment-1938020710 - - Name: NO_PREBUILT_LAMBDA + Value: !Ref GithubBranch + - Name: SOURCE_BUCKET_NAME Type: PLAINTEXT - Value: 1 + Value: !Ref PipelineSourceBucket ServiceRole: - Fn::GetAtt: - - PipelineDeployActionRole - - Arn + !GetAtt CodeDeployRole.Arn Source: - Type: CODEPIPELINE + Type: S3 + Location: !Sub ${PipelineSourceBucket}/Repository.zip BuildSpec: | version: 0.2 phases: @@ -278,174 +92,15 @@ Resources: - CDK_STACK=$(aws cloudformation list-stacks --query 'StackSummaries[?(StackName==`CDKToolkit` && StackStatus==`CREATE_COMPLETE`)].StackId' --output text) build: commands: - - git clone --single-branch --depth 1 --branch ${GITHUB_BRANCH} https://github.com/aws-samples/one-observability-demo.git - - cd ./one-observability-demo/PetAdoptions/cdk/pet_stack/ + - cd one-observability-demo-${GITHUB_BRANCH}/PetAdoptions/cdk/pet_stack - npm install - - if [ -z "$CDK_STACK" ] ; then cdk bootstrap ; else echo "Already bootstrapped" ; fi - - cdk deploy Services --context admin_role=${USER_ROLE_ARN} --require-approval=never --verbose -O ./out/out.json - - cdk deploy Applications --require-approval=never --verbose -O ./out/out.json - artifacts: - files: './one-observability-demo/PetAdoptions/cdk/pet_stack/out/out.json' + - if [ -z "$CDK_STACK" ] ; then echo "cdk bootstrap needed" ; else echo "Already bootstrapped" ; fi + - cdk synth OneObservabilityWorkshopPipeline + - cdk deploy OneObservabilityWorkshopPipeline --require-approval never LogsConfig: CloudWatchLogs: Status: ENABLED - GroupName: "/codebuild/PipelineDeployProject" - VpcConfig: - VpcId: !Ref VPC - Subnets: - - !Ref PrivateSubnet1 - SecurityGroupIds: - - Fn::GetAtt: - - NoIngressSecurityGroup - - GroupId - - Pipeline: - Type: AWS::CodePipeline::Pipeline - Properties: - RoleArn: - Fn::GetAtt: - - PipelineRole - - Arn - Stages: - - Actions: - - ActionTypeId: - Category: Source - Owner: AWS - Provider: S3 - Version: "1" - Configuration: - S3Bucket: !Ref PipelineSourceBucket - S3ObjectKey: SourceCode.zip - PollForSourceChanges: "true" - Name: S3BucketSource - OutputArtifacts: - - Name: Artifact_Source_S3Bucket - RunOrder: 1 - Name: Source - - Actions: - - ActionTypeId: - Category: Build - Owner: AWS - Provider: CodeBuild - Version: "1" - Configuration: - ProjectName: - Ref: PipelineDeployProject - InputArtifacts: - - Name: Artifact_Source_S3Bucket - OutputArtifacts: - - Name: Artifact_Build_CodeCommit - Name: Deploy - RunOrder: 2 - Name: UpdatePipeline - - ArtifactStore: - Location: - Ref: PipelineArtifactsBucket - Type: S3 - RestartExecutionOnUpdate: true - - PipelineEventRule: - Type: AWS::Events::Rule - Properties: - Description: Pipeline results notification - EventPattern: { - "source": ["aws.codepipeline"], - "detail-type": ["CodePipeline Pipeline Execution State Change"], - "detail": { - "state": ["FAILED", "CANCELED", "SUCCEEDED"] - } - } - RoleArn: !GetAtt CodePipelineReadyFunctionRole.Arn - State: "ENABLED" - Targets: - - Arn: !GetAtt CodePipelineReadyFunction.Arn - Id: "FailedPipeline" - - CodePipelineReadyFunctionRole: - Type: AWS::IAM::Role - Properties: - AssumeRolePolicyDocument: - Statement: - - Action: sts:AssumeRole - Effect: Allow - Principal: - Service: lambda.amazonaws.com - - Action: sts:AssumeRole - Effect: Allow - Principal: - Service: codebuild.amazonaws.com - - Action: sts:AssumeRole - Effect: Allow - Principal: - Service: events.amazonaws.com - Version: "2012-10-17" - ManagedPolicyArns: - - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole - - arn:aws:iam::aws:policy/AWSCodePipelineCustomActionAccess - - CodePipelineReadyFunction: - Type: AWS::Lambda::Function - Properties: - Handler: index.handler - Role: !GetAtt CodePipelineReadyFunctionRole.Arn - Code: - ZipFile: | - import json - import os - import urllib3 - import uuid - import logging - - logger = logging.getLogger() - logger.setLevel(logging.DEBUG) - - def handler(event, context): - logger.info('Received event{}'.format(event)) - - result = event['detail']['state'] - status = "FAILURE" - - if result == 'SUCCEEDED': - status = 'SUCCESS' - - encoded_body = json.dumps({ - "Status": status, - "Reason": "CodePipeline Deploy ended", - "UniqueId": str(uuid.uuid4()), - "Data": "CodePipeline Deploy ended" - }) - - logger.info('Sending response {}'.format(encoded_body)) - http = urllib3.PoolManager() - http.request('PUT', os.environ['SIGNAL_URL'], body=encoded_body) - - Runtime: python3.9 - Timeout: 900 - Environment: - Variables: - SIGNAL_URL: !Ref CodePipelineWaitHandle - - CodePipelineWaitHandle: - Type: AWS::CloudFormation::WaitConditionHandle - - CodePipelineWaitCondition: - Type: AWS::CloudFormation::WaitCondition - Properties: - Handle: !Ref CodePipelineWaitHandle - Timeout: "5400" - - PermissionForEventsToInvokeLambda: - Type: AWS::Lambda::Permission - Properties: - FunctionName: - Ref: "CodePipelineReadyFunction" - Action: "lambda:InvokeFunction" - Principal: "events.amazonaws.com" - SourceArn: - Fn::GetAtt: - - "PipelineEventRule" - - "Arn" + GroupName: "/codebuild/CDKPipelineInitialDeployment" PipelineSourceBucket: Type: AWS::S3::Bucket @@ -506,6 +161,7 @@ Resources: import cfnresponse import io import zipfile + import urllib3 def handler(event, context): # Upload the file @@ -525,18 +181,27 @@ Resources: zipper.writestr(file_name, infile_content) s3_client.put_object(Bucket=destinationBucket, Key='SourceCode.zip', Body=zip_buffer.getvalue()) - responseResult = cfnresponse.SUCCESS + branch = os.environ['GITHUB_BRANCH'] + url = f'https://github.com/aws-samples/one-observability-demo/archive/refs/heads/{branch}.zip' + http = urllib3.PoolManager() + + repozip = http.request('GET', url, preload_content=False) + if repozip.status == 200: + s3_client.put_object(Bucket=destinationBucket, Key='Repository.zip', Body=repozip.data) + responseResult = cfnresponse.SUCCESS + else: + raise Exception(f'Failed to download repository from {url}') except Exception as e: responseData['Data'] = str(e) cfnresponse.send(event, context, responseResult, responseData, "CustomResourcePhysicalID") return - Runtime: python3.9 + Runtime: python3.12 Timeout: 900 Environment: Variables: DESTINATION_BUCKET: !Ref PipelineSourceBucket - + GITHUB_BRANCH: !Ref GithubBranch PushCodeCustom: Type: Custom::Buildspec Properties: