Package: neulabs-cdk-constructs
id: indextitle: Getting StartedNeulabs CDK ConstructsThe neulabs-cdk-constructs library contains CDK-based constructs and stacks to allow the creation of cloud infrastructure on AWS.The purpose of the library is to expose modules that can facilitate the creation and maintenance of the infrastructure as code.Inside you will find generic stacks that allow the creation of services by simply instantiating a class, or constructs that implement logic to facilitate the developer and many other aspects.We decided to develop it in Typescript, using projen for repository management, and the JSII library to be able to compile the neulabs-cdk-constructs package into multiple languages.UsagePackage Installation (npm)yarn add neulabs-cdk-constructs
# or
npm install neulabs-cdk-constructsPackage Installation (python)pip install neulabs-cdk-constructsConstruct APIsExamplesLambda Function with New Relicimport {aws_lambda as neulabs_lambda} from 'neulabs-cdk-constructs';


    // Create the lambda function
    this.lambdaFn = new neulabs_lambda.NewRelicFunction(this, functionName, {
      stage: props.stage,
      functionName: functionName,
      runtime: Runtime.PYTHON_3_9,
      handler: 'app.handler',
      code: Code.fromAsset(path.join(__dirname, handler), {}),
      layers: [baseLayer, ...(layers || [])],
      environment: props.environment,
      memorySize: props.memorySize || 128,
      timeout: props.timeout || Duration.seconds(30),
      architecture: lambda.Architecture.X86_64,
      newRelicAccountId: '3540246',
      newRelicLayerName: 'NewRelicPython39',
      newRelicLayerVersion: 49,
      newRelicwithExtensionSendLogs: true,
      disableNewRelic: props.stage === 'production' ? false : true,
    });

    this.lambdaFn.addPowerToolsLayer(
      app,
      neulabs_lambda.LambdaPowerToolsLayerName.TYPESCRIPT,
      neulabs_lambda.LambdaPowerToolsLayerAccountId.TYPESCRIPT,
      20,
      props.stage === 'production' ? false : true,
      props.stage === 'production' ? 'WARGNING' : 'DEBUG'
    );Create Github OIDCAWS (Amazon Web Services) supports the use of OpenID Connect (OIDC) for identity federation. OIDC allows you to use an identity provider (such as GitHub) to authenticate users and grant them temporary security credentials to access AWS resources. Here's a brief overview of using GitHub as an identity provider with AWS OIDC:Identity Provider (GitHub): GitHub acts as the identity provider in this setup. Users authenticate with GitHub, and GitHub issues identity tokens following the OIDC standard.AWS IAM Role: In AWS, you create an IAM (Identity and Access Management) role that specifies the permissions users should have when authenticated. This role trusts the GitHub OIDC provider.GithubOIDCStack a neulabs construct: create a new stack with three roles:github-oidc-workflow-roleuser used for authenticationcdk-oidc-deploy-rolerole used for cdk deployingcdk-oidc-bootsrap-rolerole used for cdk bootstrapCreate GithubOIDCStackenvironment = process.env.ENVIRONMENT! || 'staging';

new GithubOIDCStack(app, 'OidcStack', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION,
  },
  stage: environment,
  githubUser: 'username',
  githubRepository: 'repositoryName', # You can also use '*'
  tokenAction: TokenActions.ALL,
  cdkDeployRoleAwsManagedPolicies: ['AdministratorAccess'],
});Use oidc role to authenticate the Github workflow...

permissions:
  id-token: write
  contents: read

jobs:
  ...
  deploy:
    name: OIDC Auth
    runs-on: ubuntu-20.04
    steps:
      - name: Configure aws credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          role-to-assume: arn:aws:iam::{ACCOUNT ID}:role/github-oidc-workflow-role
          aws-region: {REGION}
          mask-aws-account-id: no
  ...Create NewRelic ConnectionThe NewRelicStack implements the infrastructure to send metrics and logs to Newrelic through Kinesis and Cloudwatch Stream.
Once deployed you can copy the ARN of the 'NewRelicInfrastructure-Integrations' role and use it to configure Newrelic.new NewRelicStack(app, 'NewrelicStack', {
    env: constants.env,
    stage: constants.environment,
    newRelicBucketName: `newrelic-${constants.awsAccountId}-${constants.environment}`,
    newRelicAccountId: newRelicAccountId,
    newRelicLicenseKey: newRelicLicenseKey,
    newRelicApiUrlMetrics: EndpointUrlMetrics.EU_METRICS,
    newRelicApiUrlLogs: EndpointUrlLogs.EU_LOGS,
  });Dev modeRequirementsNode >= v16.14.0Yarn >= 1.22Setup envyarn install

npx projen default

chmod +x .husky/pre-commit

cd docs yarn installContributorsRulesRead theCONTRIBUTING.mdandCODE_OF_CONDUCT.mdbefore create pull-request.DevelopersLicenseSee theLICENSEfile for more information.