The AWS SDK + a handful of extra convenience methods.
const aws = require(`@serverless/aws-sdk-extra`)
const s3 = new aws.S3({
credentials: { accessKeyId: 'xxx', secretAccessKey: 'xxx' },
region: 'us-east-1'
})
const extras = new aws.Extras({
credentials: { accessKeyId: 'xxx', secretAccessKey: 'xxx' },
region: 'us-east-1'
})
const certificate = await extras.deployCertificate(params)
Reference
deployDistributionDomain
Deploys a CloudFront distribution domain by adding the domain to the distribution and deploying the certificate and DNS records.
const params = {
domain: 'serverless.com',
distributionId: 'xxx'
}
const {
certificateArn,
certificateStatus,
domainHostedZoneId
} = await extras.deployDistributionDomain(params)
deployCertificate
Deploys a free ACM certificate for the given domain.
const params = {
domain: 'serverless.com'
}
const { certificateArn, certificateStatus, domainHostedZoneId } = await extras.deployCertificate(
params
)
deployDistributionDns
Deploys a DNS records for a distribution domain.
const params = {
domain: 'serverless.com',
distributionUrl: 'xxx.cloudfront.net'
}
const { domainHostedZoneId } = await extras.deployDistributionDns(params)
addDomainToDistribution
Adds a domain or subdomain to a CloudFront Distribution.
const params = {
domain: 'serverless.com',
certificateArn: 'xxx:xxx',
certificateStatus: 'ISSUED'
}
const { domainHostedZoneId } = await extras.addDomainToDistribution(params)
getDomainHostedZoneId
Fetches the hosted zone id for the given domain.
const params = {
domain: 'serverless.com'
}
const { domainHostedZoneId } = await extras.getDomainHostedZoneId(params)
deployRole
Updates or creates the given role name with the given service & policy. You can specify an inline policy:
const params = {
name: 'my-role',
service: 'lambda.amazonaws.com',
policy: [
{
Effect: 'Allow',
Action: ['sts:AssumeRole'],
Resource: '*'
},
{
Effect: 'Allow',
Action: ['logs:CreateLogGroup', 'logs:CreateLogStream'],
Resource: '*'
}
]
}
const { roleArn } = await extras.deployRole(params)
Or you can specify the policy as a maanged policy arn string:
const params = {
name: 'my-role',
service: 'lambda.amazonaws.com',
policy: 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
}
const { roleArn } = await extras.deployRole(params)
If you don't specify a policy property, an admin policy will be created by default.
removeRole
Removes the given role and all its attached managed and inline policies.
const params = {
name: 'my-role'
}
await extras.removeRole(params)
removeRolePolicies
Removes all attached managed and inline policies for the given role.
const params = {
name: 'my-role'
}
await extras.removeRolePolicies(params)
deployLambda
Updates a lambda if it exists, otherwise creates a new one.
const params = {
lambdaName: 'my-lambda',
roleArn: 'aws:iam:role:arn:xxx',
lambdaSrc: 'path/to/lambda/directory'
memory: 512
vpcConfig:
securityGroupIds:
- sg-xxx
subnetIds:
- subnet-xxx
- subnet-xxx
}
const { lambdaArn, lambdaSize, lambdaSha } = await extras.deployLambda(params)
deployApigDomainDns
Deploys the DNS records for an Api Gateway V2 HTTP custom domain
const params = {
domain: 'serverless.com',
apigatewayHostedZoneId: 'qwertyuiop',
apigatewayDomainName: 'd-qwertyuiop.xxx.com'
}
const { domainHostedZoneId } = await extras.deployApigDomainDns(params)
deployAppSyncApi
Updates or creates an AppSync API
const params = {
apiName: 'my-api',
apiId: 'xxx'
}
const { apiId, apiUrls } = await extras.deployAppSyncApi(params)
deployAppSyncSchema
Updates or creates an AppSync Schema
const params = {
apiId: 'xxx',
schema: '...'
}
await extras.deployAppSyncApi(params)
deployAppSyncResolvers
Updates or creates AppSync Resolvers
const params = {
apiId,
roleName: 'my-role',
resolvers: {
Query: {
getPost: {
lambda: 'getPost'
}
},
Mutation: {
putPost: {
lambda: 'putPost'
}
}
}
}
await extras.deployAppSyncResolvers(params)
deployStack
Updates or creates a CloudFormation stack.
const inputs = {
stackName: 'my-stack',
template: {
AWSTemplateFormatVersion: '2010-09-09',
Description: 'Example Stack',
Resources: {
LogGroup: {
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: '/log/group/one',
RetentionInDays: 14
}
}
},
Outputs: {
firstStackOutput: {
Value: {
'Fn::GetAtt': ['LogGroup', 'Arn']
}
},
secondStackOutput: {
Value: {
'Fn::GetAtt': ['LogGroup', 'Arn']
}
}
}
},
capabilities: ['CAPABILITY_IAM'],
parameters: {
firstParameter: 'value'
},
role: 'arn:iam:xxx'
}
const outputs = await extras.deployStack(params)
removeStack
Removes a CloudFormation stack if it exists.
const prams = {
stackName: 'my-stack'
}
await extras.removeStack(params)