This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Full project available here: https://github.com/markilott/aws-cdk-lambda-powertools | |
import { Stack } from 'aws-cdk-lib'; | |
import { Construct } from 'constructs'; | |
import { QueryDefinition, QueryString } from 'aws-cdk-lib/aws-logs'; | |
import { | |
Color, Dashboard, GraphWidget, GraphWidgetView, LegendPosition, Metric, Row, TextWidget, | |
} from 'aws-cdk-lib/aws-cloudwatch'; | |
import { CfnGroup } from 'aws-cdk-lib/aws-xray'; | |
// ... import local types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Full code is available here: https://github.com/markilott/aws-cdk-lambda-powertools/tree/main/lib/constructs/custom-nodejs-fnc */ | |
import { Construct } from 'constructs'; | |
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'; | |
import { Runtime, Tracing } from 'aws-cdk-lib/aws-lambda'; | |
import { Duration } from 'aws-cdk-lib'; | |
import { ILogGroup } from 'aws-cdk-lib/aws-logs'; | |
import { | |
Color, GaugeWidget, GraphWidget, GraphWidgetView, IWidget, LogQueryVisualizationType, LogQueryWidget, MathExpression, Metric, SingleValueWidget, TextWidget, | |
} from 'aws-cdk-lib/aws-cloudwatch'; | |
import { CustomFunctionProps, PowerToolsEnvProps } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Full code available here: https://github.com/markilott/aws-cdk-lambda-powertools/blob/main/src/lambda/read-data/index.ts */ | |
import { AWSError, DynamoDB } from 'aws-sdk'; | |
import { Logger, injectLambdaContext } from '@aws-lambda-powertools/logger'; | |
import { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics'; | |
import { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer'; | |
import middy from '@middy/core'; | |
/** Instantiate the PowerTools instances */ | |
const logger = new Logger(); | |
const tracer = new Tracer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Duration, RemovalPolicy } from 'aws-cdk-lib'; | |
import { AttributeType, BillingMode, Table } from 'aws-cdk-lib/aws-dynamodb'; | |
import { Construct } from 'constructs'; | |
type CustomDynamoTableProps = { | |
/** Table Partition Key */ | |
partitionKey: string, | |
/** Optional Sort Key */ | |
sortKey?: string, | |
/** Table Name */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class PipelineStack extends Stack { | |
/** | |
* Creates a deployment Pipeline. | |
* Can be run for each environment to create separate | |
* pipelines for each. | |
* | |
* @param {Construct} scope | |
* @param {string} id | |
* @param {StackProps=} props | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connecting to GitHub as source in a CDK Pipeline | |
// Method 1 - Personal Access Token and Secret. | |
// Create a Personal Access Token in GitHub. | |
// Store the Token in a Secrets Manager Secret, then: | |
new CodePipeline(this, 'DemoPipeline', { | |
synth: new ShellStep('Synth', { | |
input: CodePipelineSource.gitHub('owner/reponame', 'branchname', { | |
authentication: SecretValue.secretsManager('SecretName', { jsonField: 'TOKEN_FIELD' }), | |
trigger: GitHubTrigger.WEBHOOK, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PipelinePrepStack in the Tools Account =================== | |
// Base Role for pipelines. Created here as it is required outside of the pipeline stack for cross-region deployments. | |
const pipelineBaseRole = new Role(this, 'pipelineBaseRole', { | |
assumedBy: new ServicePrincipal('codepipeline.amazonaws.com'), | |
roleName: codeCommitAccessRoleName, // We use this fixed name to attach the role in the pipeline stack | |
description: 'Role used by CodePipelines to allow for cross-account deployments', | |
}); | |
pipelineBaseRole.addToPolicy(new PolicyStatement({ | |
sid: 'AssumeRoles', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PipelinePrepStack in the Tools Account =================== | |
// Allow CodeCommit account EventBus to put events to Pipeline account EventBus | |
// This is used to trigger the pipeline from CodeCommit updates in the Development account | |
new CfnEventBusPolicy(this, 'eventsPolicy', { | |
statementId: 'CodeCommit', | |
eventBusName: 'default', | |
statement: { | |
Effect: 'Allow', | |
Principal: { AWS: `arn:aws:iam::${codeCommitAccount}:root` }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Permission Sets and Assign to Groups and Accounts | |
// Full code available here: https://github.com/markilott/aws-cdk-sso-permission-sets | |
// List of Accounts in the Organisation | |
const accountList = { | |
master: '123456789', | |
prod: '123456789', | |
dev: '123456789', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
const moment = require('moment'); | |
const docClient = new AWS.DynamoDB.DocumentClient({ | |
region: process.env.AWS_REGION, | |
}); | |
// Query where we have used a Reserved Word as the Partition Key | |
async function getCollectionList(collection) { | |
/** |
NewerOlder