AWSTemplateFormatVersion: 2010-09-09 Transform: - AWS::Serverless-2016-10-31 Parameters: ProjectId: Type: String Description: Lambda Function with API Gateway. Environment: Type: String Description: the environment... # Enable blue/green deployments using this Globals section. For instructions, see the AWS CodeStar User Guide: # https://docs.aws.amazon.com/codestar/latest/userguide/how-to-modify-serverless-project.html?icmpid=docs_acs_rm_tr # # Globals: # Function: # AutoPublishAlias: live # DeploymentPreference: # Enabled: true # Type: Canary10Percent5Minutes Resources: Lambda: Type: AWS::Serverless::Function Properties: FunctionName: !Join ['-', [!Ref 'ProjectId', !Ref 'Environment']] Role: arn:aws:iam::23452345345:role/My-Worker-Lambda Handler: index.handler Runtime: nodejs8.10 Timeout: 120 Environment: Variables: NODE_ENV: production db_connection: mongodb://WriteSvcUser:sdfgsdfgsdfgsdfg@prd-cul-mongoclient-234523453.us-east-1.elb.amazonaws.com/myDb RestApi: Type: AWS::Serverless::Api Properties: StageName: !Ref 'Environment' DefinitionBody: swagger: "2.0" info: version: "1.0" title: !Join ['-', [!Ref 'ProjectId', !Ref 'Environment']] host: "i4r9f0ntaf.execute-api.us-east-1.amazonaws.com" basePath: !Join ['', ['/', !Ref 'Environment']] schemes: - "https" paths: /: post: responses: "200": description: "200 response" x-amazon-apigateway-integration: credentials: 'arn:aws:iam::234524352345:role/My-Worker-Lambda' uri: !Join ['', ['arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:234523466554:function:', !Ref 'ProjectId', '/invocations']] passthroughBehavior: "when_no_match" httpMethod: "POST" type: "aws_proxy" options: responses: "200": description: "200 response" x-amazon-apigateway-integration: credentials: 'arn:aws:iam::133345006009:role/My-Worker-Lambda' uri: !Join ['', ['arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:133345006009:function:', !Ref 'ProjectId', '/invocations']] passthroughBehavior: "when_no_match" httpMethod: "POST" type: "aws_proxy"
Man oh man, this is something that tripped me up when moving a bunch of lambda functions over to a different region. After lots and lots of tweaks, googles, and let's-try-its I've landed upon a nice AWS CodePipeline template that I like to use for new lambda functions. Here it is below in all of its glory!
Notice how in the second-to-last line here it says, "httpMethod: "POST"" even though that is describing the OPTIONS http event. Now you DO NOT want to put "OPTIONS" as the value in here or things will go badly! Now, go forth and leverage these awesome AWS services to do incredible things!
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorThe posts on this site are written and maintained by Jim Lynch. About Jim...
Categories
All
Archives
March 2023
|