-
-
Save productinfo/e9d9c89d9e9e34422112dad9f6961c73 to your computer and use it in GitHub Desktop.
deploy serverless express app as AWS lamda function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: | |
name: soa-example | |
plugins: | |
- serverless-offline | |
- serverless-pseudo-parameters | |
# the custom section | |
custom: | |
stage: ${self:provider.stage, env:STAGE, 'dev'} | |
serverless-offline: | |
host: 0.0.0.0 | |
port: ${self:provider.port, env:PORT, '3000'} | |
package: | |
include: | |
- build/**/* | |
exclude: | |
- .infrastructure_temp/**/* | |
- build/main/**/* | |
provider: | |
region: eu-west-1 | |
stackName: ${self:service.name}-${self:provider.stage, env:STAGE, 'dev'} | |
apiName: ${self:service.name}-${self:provider.stage, env:STAGE, 'dev'}-api | |
staticBucket: infrcomp-soa-example-${self:provider.stage, env:STAGE, 'dev'} | |
environment: | |
STAGE: ${self:provider.stage, env:STAGE, 'dev'} | |
STAGE_PATH: ${self:provider.stage_path, env:STAGE_PATH, ''} | |
DOMAIN_URL: { "Fn::Join" : ["", [" https://#{ApiGatewayRestApi}", ".execute-api.eu-west-1.amazonaws.com/${self:provider.stage, env:STAGE, 'dev'}" ] ] } | |
iamRoleStatements: | |
- Effect: Allow | |
Action: | |
- s3:Get* | |
- s3:List* | |
Resource: "*" | |
stage: dev | |
stage_path: dev | |
name: aws | |
runtime: nodejs8.10 | |
functions: | |
server: | |
handler: build/server/server.default | |
events: | |
- http: 'ANY {proxy+}' | |
- cors: true | |
- http: 'POST /myservice' | |
role: ServiceOrientedAppLambdaRole | |
resources: | |
Resources: | |
StaticBucket: | |
Type: AWS::S3::Bucket | |
Properties: | |
BucketName: ${self:provider.staticBucket} | |
AccessControl: PublicRead | |
WebsiteConfiguration: | |
IndexDocument: index.html | |
CorsConfiguration: | |
CorsRules: | |
- AllowedMethods: | |
- GET | |
AllowedOrigins: | |
- "*" | |
AllowedHeaders: | |
- "*" | |
StaticBucketPolicy: | |
Type: AWS::S3::BucketPolicy | |
Properties: | |
Bucket: | |
Ref: StaticBucket | |
PolicyDocument: | |
Statement: | |
Sid: PublicReadGetObject | |
Effect: Allow | |
Principal: "*" | |
Action: | |
- s3:GetObject | |
Resource: | |
Fn::Join: ["", ["arn:aws:s3:::", {"Ref": "StaticBucket" }, "/*"]] | |
ServiceOrientedAppLambdaRole: | |
Type: AWS::IAM::Role | |
Properties: | |
RoleName: ${self:service}-${self:provider.stage, env:STAGE, 'dev'}-ServiceOrientedAppLambdaRole | |
AssumeRolePolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: | |
- lambda.amazonaws.com | |
Action: sts:AssumeRole | |
Policies: | |
- PolicyName: ${self:service}-${self:provider.stage, env:STAGE, 'dev'}-ServiceOrientedAppLambdaPolicy | |
PolicyDocument: | |
Version: "2012-10-17" | |
Statement: | |
- Effect: Allow | |
Action: | |
- "logs:*" | |
- "cloudwatch:*" | |
Resource: "*" | |
- Effect: Allow | |
Action: | |
- s3:Get* | |
- s3:List* | |
Resource: "*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment