From 78204873214c5bd4661c0c1e656ba93b2f0743f2 Mon Sep 17 00:00:00 2001 From: Alex Melnyk Date: Fri, 28 Aug 2020 12:40:32 +0200 Subject: [PATCH 1/2] add description where to find the layer arn --- docs/content/index.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/content/index.mdx b/docs/content/index.mdx index 26ab367ba4c..794c0c3f9a5 100644 --- a/docs/content/index.mdx +++ b/docs/content/index.mdx @@ -44,6 +44,16 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, SemanticVersion: 1.3.1 # change to latest semantic version available in SAR ``` +This will add a nested app stack with an output parameter `LayerVersionArn`. You can not reference layer arn within the template on the first try, this is currently not supported. + Either first run `sam deploy` and add `Layers` ARN property to the Lambda function after the deployment and run `sam deploy` again. + Or extract the `AWS::Serverless::Application` resource into a separate stack and use `Fn::ImportValue` to fetch the value. + + You can fetch the available versions via the API with: + + ```bash + aws serverlessrepo list-application-versions --application-id arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer + ``` + ## Features Utility | Description From e1c5d843c6b69817b33259cc713611d756d48769 Mon Sep 17 00:00:00 2001 From: Alex Melnyk Date: Fri, 28 Aug 2020 16:55:09 +0200 Subject: [PATCH 2/2] add layer ARN reference to docs and the example project --- docs/content/index.mdx | 11 +++++++---- example/README.md | 2 +- example/template.yaml | 9 +++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/content/index.mdx b/docs/content/index.mdx index 794c0c3f9a5..585ff0b4e5f 100644 --- a/docs/content/index.mdx +++ b/docs/content/index.mdx @@ -44,11 +44,14 @@ If using SAM, you can include this SAR App as part of your shared Layers stack, SemanticVersion: 1.3.1 # change to latest semantic version available in SAR ``` -This will add a nested app stack with an output parameter `LayerVersionArn`. You can not reference layer arn within the template on the first try, this is currently not supported. - Either first run `sam deploy` and add `Layers` ARN property to the Lambda function after the deployment and run `sam deploy` again. - Or extract the `AWS::Serverless::Application` resource into a separate stack and use `Fn::ImportValue` to fetch the value. +This will add a nested app stack with an output parameter `LayerVersionArn`, that you can reference inside your Lambda function definition: - You can fetch the available versions via the API with: +```yaml + Layers: + - !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn +``` + +You can fetch the available versions via the API with: ```bash aws serverlessrepo list-application-versions --application-id arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer diff --git a/example/README.md b/example/README.md index a54ab6ba3c3..b19f98f14f1 100644 --- a/example/README.md +++ b/example/README.md @@ -55,7 +55,7 @@ The first command will build the source of your application. The second command * **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name. * **AWS Region**: The AWS region you want to deploy your app to. * **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes. -* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modified IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. +* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modified IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command. If you are using `AWS::Serverless::Application` as a layer, you need also to pass `CAPABILITY_AUTO_EXPAND` during `sam deploy`, because it will create a nested stack for the layer. * **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application. You can find your API Gateway Endpoint URL in the output values displayed after deployment. diff --git a/example/template.yaml b/example/template.yaml index 47267d729f5..809e981edc0 100644 --- a/example/template.yaml +++ b/example/template.yaml @@ -17,6 +17,8 @@ Resources: CodeUri: hello_world/ Handler: app.lambda_handler Runtime: python3.8 + Layers: + - !GetAtt AwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn Tracing: Active # enables X-Ray tracing Environment: Variables: @@ -33,6 +35,13 @@ Resources: Path: /hello Method: get + AwsLambdaPowertoolsPythonLayer: + Type: AWS::Serverless::Application + Properties: + Location: + ApplicationId: arn:aws:serverlessrepo:eu-west-1:057560766410:applications/aws-lambda-powertools-python-layer + SemanticVersion: 1.3.1 # change to latest semantic version available in SAR + Outputs: # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function # Find out more about other implicit resources you can reference within SAM