I have the following resource defined in my serverless.yml file. It works great to create a resource for all of my various stages of development.
resources: Resources: uploadBucket: Type: AWS::S3::Bucket Properties: BucketName: ${self:service}-${self:custom.stage}-uploads visitsTable: Type: AWS::DynamoDB::Table Properties: TableName: ${self:custom.visitsTable} AttributeDefinitions: - AttributeName: userId AttributeType: S - AttributeName: visitId AttributeType: S KeySchema: - AttributeName: userId KeyType: HASH - AttributeName: visitId KeyType: RANGE ProvisionedThroughput: ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}} WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
The problem is that ... if I do sls remove
when deleting the database that it did, it also removes everything else, including the lambda functions and their api gateway endpoints, which I need to support as I have policies, explicitly set for them. How to tell serverless I want to delete only the database or S3 or something else, and not the rest?
Things I tried:
I manually deleted it on AWS, but if you do this and unlock sls, it will not create the database again! Not sure if the best way to do this is ...
Entire file without server
service: mydomain-api # Use serverless-webpack plugin to transpile ES6/ES7 plugins: - serverless-webpack - serverless-domain-manager custom: webpackIncludeModules: true stage: ${opt:stage, self:provider.stage} visitsTable: "${self:service}-visits-${self:custom.stage}" domains: prod: api.mydomain.com staging: staging-api.mydomain.com dev: dev-api.mydomain.com dynamoDbCapacityUnits: prod: 5 staging: 2 dev: 2 customDomain: basePath: "" domainName: ${self:custom.domains.${self:custom.stage}} stage: "${self:custom.stage}" certificateName: "mydomain.com" createRoute53Record: true provider: name: aws runtime: nodejs6.10 stage: prod region: us-east-1 environment: VISITS_TABLE: ${self:custom.visitsTable} # 'iamRoleStatement' defines the permission policy for the Lambda function. # In this case Lambda functions are granted with permissions to access DynamoDB. iamRoleStatements: - Effect: Allow Action: - dynamodb:DescribeTable - dynamodb:Query - dynamodb:Scan - dynamodb:GetItem - dynamodb:PutItem - dynamodb:UpdateItem - dynamodb:DeleteItem Resource: "arn:aws:dynamodb:us-east-1:*:*" functions: create: handler: src/visits/create.main events: - http: path: visits method: post cors: true authorizer: aws_iam get: handler: src/visits/get.main events: - http: path: visits/{id} method: get cors: true authorizer: aws_iam list: handler: src/visits/list.main events: - http: path: visits method: get cors: true authorizer: aws_iam update: handler: src/visits/update.main events: - http: path: visits/{id} method: put cors: true authorizer: aws_iam delete: handler: src/visits/delete.main events: - http: path: visits/{id} method: delete cors: true authorizer: aws_iam resources: Resources: uploadBucket: Type: AWS::S3::Bucket Properties: BucketName: ${self:service}-${self:custom.stage}-uploads visitsTable: Type: AWS::DynamoDB::Table Properties: TableName: ${self:custom.visitsTable} AttributeDefinitions: - AttributeName: userId AttributeType: S - AttributeName: visitId AttributeType: S KeySchema: - AttributeName: userId KeyType: HASH - AttributeName: visitId KeyType: RANGE ProvisionedThroughput: ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}} WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
source share