Skip to content

Commit

Permalink
Merge branch 'master' into open-search
Browse files Browse the repository at this point in the history
  • Loading branch information
james-jory committed May 16, 2022
2 parents 4afe62b + f32e193 commit b0edec9
Show file tree
Hide file tree
Showing 320 changed files with 32,328 additions and 13,443 deletions.
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

*Description of changes:*

*Description of testing performed to validate your changes (required if pull request includes CloudFormation or source code changes):*


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ src/aws-lambda/*/bin/
src/aws-lambda/*/package
src/aws-lambda/opensearch-pre-index/products.yaml
src/aws-lambda/personalize-delete-resources/models
src/aws-lambda/personalize-pre-create-campaigns/models
src/aws-lambda/personalize-pre-create-campaigns/data
src/aws-lambda/personalize-pre-create-resources/models
src/aws-lambda/personalize-pre-create-resources/data
src/aws-lambda/pinpoint-auto-workshop/pinpoint-templates
local/*
demo.md
Expand Down
48 changes: 35 additions & 13 deletions Developer-Instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Save your access token in a secure location.

The Retail Demo Store provides several options for managing deployments. Here are the most common ones:

### Deploy via an S3 Staging Bucket
### Option 3.1 Deploy via an S3 Staging Bucket

If you want to modify deployment templates and manage the whole deployment process yourself, you will need to configure an S3 bucket for staging Retail Demo Store deployment templates and resources prior to deployment in your own AWS account. This bucket must be in the region in which you plan to deploy.

Expand Down Expand Up @@ -64,26 +64,48 @@ If you plan to enable the automated Personalize campaign creation process at dep

It is advisable to use a Python 3 virtual environment to do this and the scripts assume that the executable pip is the Python 3 version of pip so if necessary you may need to install pip into that virtual environment (if your system defaults to a Python 2 version of pip).

There are also some Golang dependencies that need to be installed before staging:
The [stage.sh](stage.sh) script at the root of the repository must be used to upload the deployment resources to your staging S3 bucket if you use this option. The shell uses the local AWS credentials to build and push resources to your custom bucket.

Example on how to stage your project to a custom bucket and path (note the path is optional but, if specified, must end with '/'):

```bash
go get github.com/aws/aws-lambda-go/lambda
go get github.com/aws/aws-lambda-go/cfn
go get github.com/aws/aws-sdk-go
go get gopkg.in/yaml.v2
./stage.sh MY_CUSTOM_BUCKET S3_PATH/
```

The [stage.sh](stage.sh) script at the root of the repository must be used to upload the deployment resources to your staging S3 bucket if you use this option. The shell uses the local AWS credentials to build and push resources to your custom bucket.

Example on how to stage your project to a custom bucket and path (note the path is optional but, if specified, must end with '/'):
The stage script will output a path to your master deployment CloudFormation template. You can use this link to your S3 bucket to start a new deployment via the CloudFormation console in your AWS Console or use the command line below. (replace REGION, MY_CUSTOM_BUCKET and S3_PATH value)

```bash
./stage.sh mycustombucket path/
aws cloudformation deploy \
--template-file ./aws/cloudformation-templates/template.yaml \
--stack-name retaildemostore \
--capabilities CAPABILITY_NAMED_IAM \
--region REGION \
--parameter-overrides \
ResourceBucket=MY_CUSTOM_BUCKET \
ResourceBucketRelativePath=S3_PATH \
SourceDeploymentType="CodeCommit" \
AlexaSkillId="" \
AlexaAmazonPayDefaultSandboxEmail="" \
ResourceBucketRelativePath="" \
mParticleSecretKey="" \
AmazonPayPublicKeyId="" \
mParticleApiKey="" \
mParticleS2SSecretKey="" \
mParticleS2SApiKey="" \
mParticleOrgId="" \
GoogleAnalyticsMeasurementId="" \
PinpointSMSLongCode="" \
PinpointEmailFromAddress="" \
SegmentWriteKey="" \
AmazonPayPrivateKey="" \
AmazonPayStoreId="" \
AmazonPayMerchantId="" \
OptimizelySdkKey="" \
GitHubToken="" \
AmplitudeApiKey=""
```

The stage script will output a path to your master deployment CloudFormation template. You can use this link to your S3 bucket to start a new deployment via the CloudFormation console in your AWS Console.

### Deploy Infrastructure from the Main Repo, Deploy Application and Services via GitHub
### Option 3.2 Deploy Infrastructure from the Main Repo, Deploy Application and Services via GitHub

If you only want to modify the web user interface, or the Retail Demo Store backend services, you can deploy Retail Demo Store using the options below, and issue commits in your own fork via GitHub to trigger a re-deploy. This will allow you to push changes to the Retail Demo Store services and web user interface using a CodeDeploy pipeline.

Expand Down
30 changes: 24 additions & 6 deletions README.md

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions aws/cloudformation-templates/alexa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
AWSTemplateFormatVersion: 2010-09-09


Description: >
This template deploys the supporting infrastructure for the C-Store Alexa Skill, in particular,
the back-end Lambda function supporting the skill and the role that gives Alexa permission
to invoke it.
Parameters:

AlexaSkillId:
Type: String
Description: >
The ID of the Alexa Skill that is allowed to invoke this Alexa Lambda.
PinpointAppId:
Type: String

ResourceBucket:
Type: String
Description: >
S3 bucket name where the Retail Demo Store deployment resources are staged (product images, nested CloudFormation templates, source code snapshot,
notebooks, deployment Lambda code, etc).
ResourceBucketRelativePath:
Type: String
Description: >
Optional path in the Deployment Resources Staging bucket where the deployment resources are stored (e.g. path/path2/).
Leave blank if resources are at the root of the Staging Resource Bucket. If specified, MUST end with '/'.
ProductsServiceExternalUrl:
Type: String

LocationServiceExternalUrl:
Type: String

OrdersServiceExternalUrl:
Type: String

CartsServiceExternalUrl:
Type: String

RecommendationsServiceExternalUrl:
Type: String

LocationResourceName:
Type: String

AmazonPayMerchantId:
Type: String

AlexaAmazonPayDefaultSandboxEmail:
Type: String
Description: Fallback email for testing if no Cognito integration possible (e.g. testing on Alexa web simulator).


Resources:

AlexaSkillIAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: "AlexaLambdaExecutionPolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- mobiletargeting:SendMessages
Resource: !Sub "arn:aws:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${PinpointAppId}/messages"
- Effect: Allow
Action:
- geo:SearchPlaceIndexForPosition
- geo:SearchPlaceIndexForText
Resource:
- !Sub 'arn:aws:geo:${AWS::Region}:${AWS::AccountId}:place-index/${LocationResourceName}*'
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
- logs:CreateLogGroup
Resource: '*'

AlexaSkillFunction:
Type: AWS::Lambda::Function
Properties:
Code:
S3Bucket: !Ref ResourceBucket
S3Key: !Sub '${ResourceBucketRelativePath}aws-lambda/alexa-skill-lambda.zip'
Handler: alexa-skill-lambda.lambda_handler
Runtime: python3.8
Role: !GetAtt AlexaSkillIAMRole.Arn
MemorySize: 512
Timeout: 60
Environment:
Variables:
OrdersServiceExternalUrl: !Ref OrdersServiceExternalUrl
CartsServiceExternalUrl: !Ref CartsServiceExternalUrl
RecommendationsServiceExternalUrl: !Ref RecommendationsServiceExternalUrl
ProductsServiceExternalUrl: !Ref ProductsServiceExternalUrl
LocationServiceExternalUrl: !Ref LocationServiceExternalUrl
PinpointAppId: !Ref PinpointAppId
LocationResourceName: !Ref LocationResourceName
AmazonPayMerchantId: !Ref AmazonPayMerchantId
AlexaAmazonPayDefaultSandboxEmail: !Ref AlexaAmazonPayDefaultSandboxEmail

AlexaSkillFunctionEventPermission:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
FunctionName: !GetAtt AlexaSkillFunction.Arn
Principal: alexa-appkit.amazon.com
EventSourceToken: !Ref AlexaSkillId

AlexaSkillFunctionEventPermissionSmartHome:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:invokeFunction
FunctionName: !GetAtt AlexaSkillFunction.Arn
Principal: alexa-connectedhome.amazon.com
EventSourceToken: !Ref AlexaSkillId

AlexaSkillFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${AlexaSkillFunction}
RetentionInDays: 14

Outputs:

AlexaSkillEndpointArn:
Description: LambdaARN for the regional endpoint
Value: !GetAtt AlexaSkillFunction.Arn

AlexaExecutionRoleArn:
Description: ARN of execution role required by Alexa-hosted Lambda function.
Value: !GetAtt AlexaSkillIAMRole.Arn
Loading

0 comments on commit b0edec9

Please sign in to comment.