How to use @aws-cdk/aws-sam - 6 common examples

To help you get started, we’ve selected a few @aws-cdk/aws-sam examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / @aws-cdk / aws-rds / lib / secret-rotation.ts View on Github external
if (!props.target.connections.defaultPort) {
      throw new Error('The `target` connections must have a default port range.');
    }

    const rotationFunctionName = this.node.uniqueId;

    const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
      vpc: props.vpc
    });

    const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets);

    props.target.connections.allowDefaultPortFrom(securityGroup);

    const application = new serverless.CfnApplication(this, 'Resource', {
      location: props.application,
      parameters: {
        endpoint: `https://secretsmanager.${Stack.of(this).region}.${Stack.of(this).urlSuffix}`,
        functionName: rotationFunctionName,
        vpcSecurityGroupIds: securityGroup.securityGroupId,
        vpcSubnetIds: subnetIds.join(',')
      }
    });

    // Dummy import to reference this function in the rotation schedule
    const rotationLambda = lambda.Function.fromFunctionArn(this, 'RotationLambda', Stack.of(this).formatArn({
      service: 'lambda',
      resource: 'function',
      sep: ':',
      resourceName: rotationFunctionName
    }));
github simalexan / api-lambda-save-dynamodb / lib / api-lambda-save-dynamodb-stack.ts View on Github external
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const tableName = 'twitchViewers';

    const primaryKeyName = 'viewerId';
    const table = new Table(this, 'viewers-table', {
      tableName: tableName,
      partitionKey: {
        name: primaryKeyName,
        type: AttributeType.String
      },
      billingMode: BillingMode.PayPerRequest
    });

    const api = new CfnApi(this, 'viewersApi', {
      stageName: 'prod',
      cors: '"*"'
    });

    new CfnFunction(this, 'SaveToDynamoDB', {
      codeUri: new AssetCode('src').path,
      handler: 'index.handler',
      runtime: 'nodejs8.10',
      environment: {
        variables: {
          TABLE_NAME: table.tableName,
          PRIMARY_KEY: primaryKeyName
        }
      },
      policies: `
        - DynamoDBCrudPolicy:
github simalexan / api-lambda-save-dynamodb / lib / api-lambda-save-dynamodb-stack.js View on Github external
constructor(scope, id, props) {
        super(scope, id, props);
        const tableName = 'twitchViewers';
        const primaryKeyName = 'viewerId';
        const table = new aws_dynamodb_1.Table(this, 'viewers-table', {
            tableName: tableName,
            partitionKey: {
                name: primaryKeyName,
                type: aws_dynamodb_1.AttributeType.String
            },
            billingMode: aws_dynamodb_1.BillingMode.PayPerRequest
        });
        const api = new aws_sam_1.CfnApi(this, 'viewersApi', {
            stageName: 'prod',
            cors: '"*"'
        });
        new aws_sam_1.CfnFunction(this, 'SaveToDynamoDB', {
            codeUri: new aws_lambda_1.AssetCode('src').path,
            handler: 'index.handler',
            runtime: 'nodejs8.10',
            environment: {
                variables: {
                    TABLE_NAME: table.tableName,
                    PRIMARY_KEY: primaryKeyName
                }
            },
            policies: `
        - DynamoDBCrudPolicy:
            TableName: ${tableName}`,
github fourTheorem / slic-starter / cicd / lib / pipeline-dashboard.ts View on Github external
constructor(scope: cdk.Construct, id: string) {
    super(scope, id)
    new CfnApplication(scope, `${id}App`, {
      location: {
        applicationId:
          'arn:aws:serverlessrepo:us-east-1:923120264911:applications/pipeline-dashboard',
        semanticVersion: '0.0.7'
      },
      parameters: {
        PipelinePattern: '*'
      }
    })
  }
}
github simalexan / api-lambda-save-dynamodb / lib / api-lambda-save-dynamodb-stack.ts View on Github external
const primaryKeyName = 'viewerId';
    const table = new Table(this, 'viewers-table', {
      tableName: tableName,
      partitionKey: {
        name: primaryKeyName,
        type: AttributeType.String
      },
      billingMode: BillingMode.PayPerRequest
    });

    const api = new CfnApi(this, 'viewersApi', {
      stageName: 'prod',
      cors: '"*"'
    });

    new CfnFunction(this, 'SaveToDynamoDB', {
      codeUri: new AssetCode('src').path,
      handler: 'index.handler',
      runtime: 'nodejs8.10',
      environment: {
        variables: {
          TABLE_NAME: table.tableName,
          PRIMARY_KEY: primaryKeyName
        }
      },
      policies: `
        - DynamoDBCrudPolicy:
            TableName: ${tableName}`,
      events: {
        save: {
          type: 'Api',
          properties: {
github simalexan / api-lambda-save-dynamodb / lib / api-lambda-save-dynamodb-stack.js View on Github external
super(scope, id, props);
        const tableName = 'twitchViewers';
        const primaryKeyName = 'viewerId';
        const table = new aws_dynamodb_1.Table(this, 'viewers-table', {
            tableName: tableName,
            partitionKey: {
                name: primaryKeyName,
                type: aws_dynamodb_1.AttributeType.String
            },
            billingMode: aws_dynamodb_1.BillingMode.PayPerRequest
        });
        const api = new aws_sam_1.CfnApi(this, 'viewersApi', {
            stageName: 'prod',
            cors: '"*"'
        });
        new aws_sam_1.CfnFunction(this, 'SaveToDynamoDB', {
            codeUri: new aws_lambda_1.AssetCode('src').path,
            handler: 'index.handler',
            runtime: 'nodejs8.10',
            environment: {
                variables: {
                    TABLE_NAME: table.tableName,
                    PRIMARY_KEY: primaryKeyName
                }
            },
            policies: `
        - DynamoDBCrudPolicy:
            TableName: ${tableName}`,
            events: {
                save: {
                    type: 'Api',
                    properties: {

@aws-cdk/aws-sam

The CDK Construct Library for the AWS Serverless Application Model (SAM) resources

Apache-2.0
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis