UNPKG

@webda/aws

Version:

Webda AWS Services implementation

317 lines (316 loc) 8.15 kB
import { CloudFormation } from "@aws-sdk/client-cloudformation"; import { ContainerResources } from "@webda/shell"; import { AWSDeployer, AWSDeployerResources } from "./index.js"; import { LambdaPackagerResources } from "./lambdapackager.js"; /** * Build Docker image for AWS * * @todo Add X-Ray agent */ interface AWSDockerResources extends ContainerResources { /** * Create the ECR automatically */ includeRepository: boolean; } /** * CloudFormation deployer resources * * Define how to generate CloudFormation resources */ interface CloudFormationDeployerResources extends AWSDeployerResources { /** * @todo */ repositoryNamespace: string; /** * AssetsBucket to copy Lambda package, CloudFormation template and OpenAPI definitions */ AssetsBucket?: string; /** * Prefix to use when copying to the AssetsBucket */ AssetsPrefix?: string; /** * CREATE is the default * * IMPORT is not well supported as AWS support seems weak aswell */ ChangeSetType?: "CREATE" | "IMPORT"; /** * Resources to import in the template */ ResourcesToImport?: any[]; /** * Format for CloudFormation template * * YAML format can generate issue */ Format?: "JSON" | "YAML"; /** * How to name CloudFormation.json on AssetsBucket */ StackName?: string; /** * */ FileName?: string; DomainName?: string; APIGateway?: { Name?: string; }; APIGatewayDeployment?: {}; APIGatewayStage?: { StageName?: string; }; APIGatewayDomain?: { DomainName: string; CertificateArn?: string; EndpointConfiguration?: { Types: string[]; }; SecurityPolicy?: string; }; APIGatewayBasePathMapping?: { BasePath?: string; DomainName?: string; RestApiId?: string; Stage?: string; }; APIGatewayV2?: {}; APIGatewayV2Deployment?: {}; APIGatewayV2Stage?: {}; APIGatewayV2Domain?: { DomainName: string; DomainNameConfigurations?: { CertificateArn?: string; CertificateName?: string; EndpointType?: string; SecurityPolicy?: string; }[]; MutualTlsAuthentication: { TruststoreUri?: string; TruststoreVersion?: string; }; Tags?: any; }; APIGatewayV2ApiMapping?: { BasePath?: string; DomainName?: string; ApiId?: string; Stage?: string; }; Role?: { AssumeRolePolicyDocument?: { Statement: any[]; Version?: string; }; Path?: any; Policies?: any; RoleName?: any; }; StackOptions?: any; Resources?: {}; /** * Policy to create * * This deployer can automatically create the policy tailored to your application needs * All the AWS services from this package advertise the type of permissions they need * */ Policy?: { /** * PolicyName to use */ PolicyName?: any; PolicyDocument?: any; Roles?: any[]; USers?: any[]; Groups?: any[]; }; /** * Name of your OpenAPI inside the AssetsBucket */ OpenAPIFileName?: string; /** * Title for your OpenAPI definition * https://github.com/loopingz/webda.io/issues/17 */ OpenAPITitle?: string; /** * Description of the OpenAPI * https://github.com/loopingz/webda.io/issues/17 */ Description?: string; /** * How to build the Lambda package */ LambdaPackager?: LambdaPackagerResources; /** * Deploy a Lambda package with your application */ Lambda?: { /** * FunctionName to create */ FunctionName?: string; /** * Role to set on the function */ Role?: any; /** * Type of Runtime to use * * @default "nodejs14.x" */ Runtime?: any; /** * Should not require to be overriden * @default "node_modules/@webda/aws/lib/deployers/lambda-entrypoint.handler" */ Handler?: string; /** * Memory to set on the Lambda * * Less memory is less expensive/ms but slower * @default 2048 */ MemorySize?: number; /** * Timeout in seconds for your Lambda * * @default 30 */ Timeout?: number; }; Fargate?: {}; Docker?: AWSDockerResources; /** * Deploy static website */ Statics?: [ { /** * Domain name to deploy on */ DomainName: string; /** * CloudFront parameter to add */ CloudFront: any; /** * Source on local folder */ Source: string; /** * Path to store on the AssetsBucket */ AssetsPath?: string; } ]; /** * Import Open API to APIGateway * * This is the restApiId to import to */ APIGatewayImportOpenApi?: string; Workers?: []; /** * Keep locally the Lambda package after S3 uploads */ KeepPackage?: boolean; /** * Any additional CloudFormation resources */ CustomResources: any; } declare const LAMBDA_LATEST_VERSION = "nodejs14.x"; /** * Deploy the application and its resources using AWS CloudFormation * * @WebdaDeployer WebdaAWSDeployer/CloudFormation */ export default class CloudFormationDeployer extends AWSDeployer<CloudFormationDeployerResources> { template: any; result: any; openapiS3Object: { key: any; src: any; }; constructor(manager: any, resources: any); defaultResources(): Promise<void>; deploy(): Promise<any>; /** * Upload any asset to bucket */ uploadStatics(): Promise<void>; createStatic(info: any): Promise<void>; /** * Copy the CloudFormation template to the Assets bucket */ sendCloudFormationTemplate(): Promise<void>; /** * Delete the CloudFormation stack * @returns */ deleteCloudFormation(): Promise<any>; /** * * @param ref * @param domain * @param HostedZoneId * @returns */ createCloudFormationDNSEntry(ref: any, domain: string, HostedZoneId: any): Promise<void>; importOpenApi(openapi: any): Promise<void>; /** * Create the stack changeset * @param cloudformation * @returns */ createCloudFormationChangeSet(cloudformation: CloudFormation): Promise<any>; /** * Upload and create the cloudformation stack or update it * @returns */ createCloudFormation(): Promise<void>; /** * Pause for x seconds * @param seconds */ sleep(sec: number): Promise<void>; Resources(): Promise<void>; getRegion(): string; completeOpenAPI(openapi: any): Promise<any>; getStringified(object: any, filename: any, addPrefix?: boolean): { key: any; src: any; }; APIGateway(): Promise<void>; APIGatewayDomain(): Promise<void>; Policy(): Promise<void>; addAssumeRolePolicyStatement(...statements: any[]): void; Role(): Promise<void>; Lambda(): Promise<void>; buildDocker(): Promise<void>; Fargate(): Promise<void>; generateLambdaPackage(): Promise<{ S3Bucket: string; S3Key: string; }>; /** * Init the project on AWS * * It creates a CloudFormation stack with one ECR and one Bucket * and save their name in package.json(webda.aws) * * If you want to use your own ECR and S3 for assets just add * them inside your package.json with `webda.aws.AssetsBucket` and * `webda.aws.Repository` * * @param console * @returns */ static init(console: any): Promise<-1 | 0>; } export { CloudFormationDeployer, LAMBDA_LATEST_VERSION };